Skip to content

Commit

Permalink
feat: Implementation of container policies #2
Browse files Browse the repository at this point in the history
  • Loading branch information
djenczewski committed Nov 26, 2024
1 parent b128e00 commit fe89ea1
Show file tree
Hide file tree
Showing 21 changed files with 840 additions and 83 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// PrivMX Endpoint Java Extra.
// Copyright © 2024 Simplito sp. z o.o.
//
// This file is part of the PrivMX Platform (https://privmx.dev).
// This software is Licensed under the MIT License.
//
// See the License for the specific language governing permissions and
// limitations under the License.
//

package com.simplito.java.privmx_endpoint_extra.policies;

public final class BasePolicyValue extends PolicyValue {

BasePolicyValue(String value) {
super(value);
}

public static final BasePolicyValue DEFAULT = new BasePolicyValue("default");
public static final BasePolicyValue INHERIT = new BasePolicyValue("inherit");
public static final BasePolicyValue YES = new BasePolicyValue("yes");
public static final BasePolicyValue NO = new BasePolicyValue("no");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// PrivMX Endpoint Java Extra.
// Copyright © 2024 Simplito sp. z o.o.
//
// This file is part of the PrivMX Platform (https://privmx.dev).
// This software is Licensed under the MIT License.
//
// See the License for the specific language governing permissions and
// limitations under the License.
//

package com.simplito.java.privmx_endpoint_extra.policies;

public class ContainerPolicyChainValue extends ContainerPolicyValue {


ContainerPolicyChainValue(String value) {
super(value);
}

public ContainerPolicyChainValue OR(ContainerPolicyChainValue policy) {
return new ContainerPolicyChainValue(value + "," + policy.value);
}


public ContainerPolicyChainValue AND(ContainerPolicyChainValue policy) {
return new ContainerPolicyChainValue(value + "&" + policy.value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// PrivMX Endpoint Java Extra.
// Copyright © 2024 Simplito sp. z o.o.
//
// This file is part of the PrivMX Platform (https://privmx.dev).
// This software is Licensed under the MIT License.
//
// See the License for the specific language governing permissions and
// limitations under the License.
//

package com.simplito.java.privmx_endpoint_extra.policies;

public class ContainerPolicyValue extends PolicyValue {
ContainerPolicyValue(String value) {
super(value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// PrivMX Endpoint Java Extra.
// Copyright © 2024 Simplito sp. z o.o.
//
// This file is part of the PrivMX Platform (https://privmx.dev).
// This software is Licensed under the MIT License.
//
// See the License for the specific language governing permissions and
// limitations under the License.
//

package com.simplito.java.privmx_endpoint_extra.policies;


public class ContainerPolicyValues {
public static final ContainerPolicyValue DEFAULT = new ContainerPolicyValue("default");
public static final ContainerPolicyValue INHERIT = new ContainerPolicyValue("inherit");
public static final ContainerPolicyValue NONE = new ContainerPolicyValue("none");
public static final ContainerPolicyValue ALL = new ContainerPolicyValue("all");
public static final ContainerPolicyChainValue USER = new ContainerPolicyChainValue("user");
public static final ContainerPolicyChainValue MANAGER = new ContainerPolicyChainValue("manager");
public static final ContainerPolicyChainValue OWNER = new ContainerPolicyChainValue("owner");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// PrivMX Endpoint Java Extra.
// Copyright © 2024 Simplito sp. z o.o.
//
// This file is part of the PrivMX Platform (https://privmx.dev).
// This software is Licensed under the MIT License.
//
// See the License for the specific language governing permissions and
// limitations under the License.
//

package com.simplito.java.privmx_endpoint_extra.policies;

public class ItemPolicyChainValue extends ItemPolicyValue {

ItemPolicyChainValue(String value) {
super(value);
}

public ItemPolicyChainValue OR(ItemPolicyChainValue policy) {
return new ItemPolicyChainValue(value + "," + policy.value);
}

public ItemPolicyChainValue AND(ItemPolicyChainValue policy) {
return new ItemPolicyChainValue(value + "&" + policy.value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// PrivMX Endpoint Java Extra.
// Copyright © 2024 Simplito sp. z o.o.
//
// This file is part of the PrivMX Platform (https://privmx.dev).
// This software is Licensed under the MIT License.
//
// See the License for the specific language governing permissions and
// limitations under the License.
//

package com.simplito.java.privmx_endpoint_extra.policies;

public class ItemPolicyValue extends PolicyValue {
ItemPolicyValue(String value) {
super(value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// PrivMX Endpoint Java Extra.
// Copyright © 2024 Simplito sp. z o.o.
//
// This file is part of the PrivMX Platform (https://privmx.dev).
// This software is Licensed under the MIT License.
//
// See the License for the specific language governing permissions and
// limitations under the License.
//

package com.simplito.java.privmx_endpoint_extra.policies;

public class ItemPolicyValues {
public static final ItemPolicyValue DEFAULT = new ItemPolicyValue("default");
public static final ItemPolicyValue NONE = new ItemPolicyValue("none");
public static final ItemPolicyValue ALL = new ItemPolicyValue("all");
public static final ItemPolicyChainValue USER = new ItemPolicyChainValue("user");
public static final ItemPolicyChainValue MANAGER = new ItemPolicyChainValue("manager");
public static final ItemPolicyChainValue OWNER = new ItemPolicyChainValue("owner");
public static final ItemPolicyChainValue ITEM_OWNER = new ItemPolicyChainValue("itemOwner");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// PrivMX Endpoint Java Extra.
// Copyright © 2024 Simplito sp. z o.o.
//
// This file is part of the PrivMX Platform (https://privmx.dev).
// This software is Licensed under the MIT License.
//
// See the License for the specific language governing permissions and
// limitations under the License.
//

package com.simplito.java.privmx_endpoint_extra.policies;

public class PolicyValue {
public final String value;

PolicyValue(String value) {
this.value = value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
//
// PrivMX Endpoint Java Extra.
// Copyright © 2024 Simplito sp. z o.o.
//
// This file is part of the PrivMX Platform (https://privmx.dev).
// This software is Licensed under the MIT License.
//
// See the License for the specific language governing permissions and
// limitations under the License.
//

package com.simplito.java.privmx_endpoint_extra.policies.builders;

import com.simplito.java.privmx_endpoint.model.ContainerPolicy;
import com.simplito.java.privmx_endpoint.model.ContainerPolicyWithoutItem;
import com.simplito.java.privmx_endpoint.model.ItemPolicy;
import com.simplito.java.privmx_endpoint_extra.policies.BasePolicyValue;
import com.simplito.java.privmx_endpoint_extra.policies.ContainerPolicyValue;

public class ContainerPolicyBuilder {

private String get;
private String update;
private String delete;
private String updatePolicy;
private String updaterCanBeRemovedFromManagers;
private String ownerCanBeRemovedFromManagers;
private ItemPolicy item;

public ContainerPolicyBuilder() {
}

public ContainerPolicyBuilder(ContainerPolicy containerPolicy) {
this.get = containerPolicy.get;
this.update = containerPolicy.update;
this.delete = containerPolicy.delete;
this.updatePolicy = containerPolicy.updatePolicy;
this.updaterCanBeRemovedFromManagers = containerPolicy.updaterCanBeRemovedFromManagers;
this.ownerCanBeRemovedFromManagers = containerPolicy.ownerCanBeRemovedFromManagers;
this.item = containerPolicy.item;
}

public ContainerPolicyBuilder(ContainerPolicyWithoutItem containerPolicyWithoutItem) {
this.get = containerPolicyWithoutItem.get;
this.update = containerPolicyWithoutItem.update;
this.delete = containerPolicyWithoutItem.delete;
this.updatePolicy = containerPolicyWithoutItem.updatePolicy;
this.updaterCanBeRemovedFromManagers = containerPolicyWithoutItem.updaterCanBeRemovedFromManagers;
this.ownerCanBeRemovedFromManagers = containerPolicyWithoutItem.ownerCanBeRemovedFromManagers;
}

ContainerPolicyBuilder setGet(ContainerPolicyValue policyValue) {
this.get = policyValue.value;
return this;
}

ContainerPolicyBuilder setUpdate(ContainerPolicyValue policyValue) {
this.update = policyValue.value;
return this;
}

ContainerPolicyBuilder setDelete(ContainerPolicyValue policyValue) {
this.delete = policyValue.value;
return this;
}

ContainerPolicyBuilder setUpdatePolicy(ContainerPolicyValue policyValue) {
this.updatePolicy = policyValue.value;
return this;
}

ContainerPolicyBuilder setUpdaterCanBeRemovedFromManagers(BasePolicyValue policyValue) {
this.updaterCanBeRemovedFromManagers = policyValue.value;
return this;
}

ContainerPolicyBuilder setOwnerCanBeRemovedFromManagers(BasePolicyValue policyValue) {
this.ownerCanBeRemovedFromManagers = policyValue.value;
return this;
}

ContainerPolicyBuilder setItem(ItemPolicy item) {
this.item = item;
return this;
}

ContainerPolicyWithoutItem buildWithoutItem() {
return new ContainerPolicyWithoutItem(
get,
update,
delete,
updatePolicy,
updaterCanBeRemovedFromManagers,
ownerCanBeRemovedFromManagers
);
}

ContainerPolicy build() {
return new ContainerPolicy(
get,
update,
delete,
updatePolicy,
updaterCanBeRemovedFromManagers,
ownerCanBeRemovedFromManagers,
item
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//
// PrivMX Endpoint Java Extra.
// Copyright © 2024 Simplito sp. z o.o.
//
// This file is part of the PrivMX Platform (https://privmx.dev).
// This software is Licensed under the MIT License.
//
// See the License for the specific language governing permissions and
// limitations under the License.
//

package com.simplito.java.privmx_endpoint_extra.policies.builders;

import com.simplito.java.privmx_endpoint.model.ItemPolicy;
import com.simplito.java.privmx_endpoint_extra.policies.ItemPolicyValue;

public class ItemPolicyBuilder {
private String get;
private String listMy;
private String listAll;
private String create;
private String update;
private String delete;

public ItemPolicyBuilder() {

}

ItemPolicyBuilder setGet(ItemPolicyValue policyValue) {
this.get = policyValue.value;
return this;
}

ItemPolicyBuilder setListMy(ItemPolicyValue policyValue) {
this.listMy = policyValue.value;
return this;
}

ItemPolicyBuilder setListAll(ItemPolicyValue policyValue) {

this.listAll = policyValue.value;
return this;
}

ItemPolicyBuilder setCreate(ItemPolicyValue policyValue) {
this.create = policyValue.value;
return this;
}

ItemPolicyBuilder setUpdate(ItemPolicyValue policyValue) {
this.update = policyValue.value;
return this;
}

ItemPolicyBuilder setDelete(ItemPolicyValue policyValue) {
this.delete = policyValue.value;
return this;
}

ItemPolicy build() {
return new ItemPolicy(
get,
listMy,
listAll,
create,
update,
delete
);
}
}
Loading

0 comments on commit fe89ea1

Please # to comment.