Skip to content

Commit

Permalink
Merge pull request eclipse-tractusx#530 from catenax-ng/TRI-1593-poli…
Browse files Browse the repository at this point in the history
…cy-store-api-extension

feat(irs-policy-store): [TRI-1593] Policy Store API Extension
  • Loading branch information
ds-ext-abugajewski authored Sep 21, 2023
2 parents 3c43329 + fada26b commit 0da8794
Show file tree
Hide file tree
Showing 13 changed files with 456 additions and 19 deletions.
61 changes: 61 additions & 0 deletions docs/src/api/irs-v1.0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1610,11 +1610,54 @@ components:
type: string
manufacturerName:
type: string
Constraint:
type: object
additionalProperties: false
properties:
leftOperand:
type: string
operator:
type: string
enum:
- eq
- neq
- lt
- gt
- in
- lteq
- gteq
- isA
- hasPart
- isPartOf
- isOneOf
- isAllOf
- isNoneOf
rightOperand:
type: array
items:
type: string
Constraints:
type: object
additionalProperties: false
properties:
and:
type: array
items:
$ref: '#/components/schemas/Constraint'
or:
type: array
items:
$ref: '#/components/schemas/Constraint'
CreatePolicyRequest:
type: object
additionalProperties: false
description: Request to add a policy
properties:
permissions:
type: array
description: List of permissions that will be added to the Policy on creation.
items:
$ref: '#/components/schemas/Permission'
policyId:
type: string
description: The ID of the policy to add
Expand All @@ -1623,6 +1666,7 @@ components:
format: date-time
description: Timestamp after which the policy will no longer be accepted in negotiations
required:
- permissions
- policyId
- validUntil
EdcNotification:
Expand Down Expand Up @@ -2040,13 +2084,30 @@ components:
required:
- bpn
- globalAssetId
Permission:
type: object
additionalProperties: false
properties:
action:
type: string
enum:
- ACCESS
- USE
constraints:
type: array
items:
$ref: '#/components/schemas/Constraints'
Policy:
type: object
additionalProperties: false
properties:
createdOn:
type: string
format: date-time
permissions:
type: array
items:
$ref: '#/components/schemas/Permission'
policyId:
type: string
validUntil:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/********************************************************************************
* Copyright (c) 2021,2022,2023
* 2022: ZF Friedrichshafen AG
* 2022: ISTOS GmbH
* 2022,2023: Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
* 2022,2023: BOSCH AG
* Copyright (c) 2021,2022,2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
package org.eclipse.tractusx.irs.policystore.models;

import java.util.List;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

/**
* A Constraint object used as an element of collection in Permission
*/
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class Constraint {

private String leftOperand;
private OperatorType operator;
private List<String> rightOperand;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/********************************************************************************
* Copyright (c) 2021,2022,2023
* 2022: ZF Friedrichshafen AG
* 2022: ISTOS GmbH
* 2022,2023: Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
* 2022,2023: BOSCH AG
* Copyright (c) 2021,2022,2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
package org.eclipse.tractusx.irs.policystore.models;

import java.util.List;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

/**
* A Constraint containing two collections of Constraints
*/
@Getter
@AllArgsConstructor
@NoArgsConstructor
@SuppressWarnings("PMD.ShortVariable")
public class Constraints {

private List<Constraint> and;
private List<Constraint> or;

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package org.eclipse.tractusx.irs.policystore.models;

import java.time.OffsetDateTime;
import java.util.List;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
Expand All @@ -37,6 +38,8 @@
@Schema(description = "Request to add a policy")
public record CreatePolicyRequest(@Schema(description = "The ID of the policy to add") @NotNull String policyId,

@Schema(description = "Timestamp after which the policy will no longer be accepted in negotiations") @NotNull OffsetDateTime validUntil) {
@Schema(description = "Timestamp after which the policy will no longer be accepted in negotiations") @NotNull OffsetDateTime validUntil,
@Schema(description = "List of permissions that will be added to the Policy on creation.") @NotNull List<Permission> permissions
) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/********************************************************************************
* Copyright (c) 2021,2022,2023
* 2022: ZF Friedrichshafen AG
* 2022: ISTOS GmbH
* 2022,2023: Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
* 2022,2023: BOSCH AG
* Copyright (c) 2021,2022,2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
package org.eclipse.tractusx.irs.policystore.models;

import java.util.NoSuchElementException;
import java.util.stream.Stream;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.Getter;

/**
* List of Operator Type that can be used to build Constraints
*/
@JsonSerialize(using = ToStringSerializer.class)
@Getter
public enum OperatorType {

EQ("eq", "Equals to"),
NEQ("neq", "Not equal to"),
LT("lt", "Less than"),
GT("gt", "Greater than"),
IN("in", "In"),
LTEQ("lteq", "Less than or equal to"),
GTEQ("gteq", "Greater than or equal to"),
ISA("isA", "Is a"),
HASPART("hasPart", "Has part"),
ISPARTOF("isPartOf", "Is part of"),
ISONEOF("isOneOf", "Is one of"),
ISALLOF("isAllOf", "Is all of"),
ISNONEOF("isNoneOf", "Is none of");

private final String code;
private final String label;

OperatorType(final String code, final String label) {
this.code = code;
this.label = label;
}

@JsonCreator
public static OperatorType fromValue(final String value) {
return Stream.of(OperatorType.values())
.filter(operatorType -> operatorType.code.equals(value))
.findFirst()
.orElseThrow(() -> new NoSuchElementException("Unsupported OperatorType: " + value));
}

/**
* @return convert OperatorType to string value
*/
@Override
public String toString() {
return code;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/********************************************************************************
* Copyright (c) 2021,2022,2023
* 2022: ZF Friedrichshafen AG
* 2022: ISTOS GmbH
* 2022,2023: Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
* 2022,2023: BOSCH AG
* Copyright (c) 2021,2022,2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
package org.eclipse.tractusx.irs.policystore.models;

import java.util.List;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

/**
* A Permission object gather PolicyType with list of Constraints and its relation
*/
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class Permission {

private PolicyType action;
private List<Constraints> constraints;


}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package org.eclipse.tractusx.irs.policystore.models;

import java.time.OffsetDateTime;
import java.util.List;

import lombok.AllArgsConstructor;
import lombok.Getter;
Expand All @@ -40,6 +41,7 @@ public class Policy {
private String policyId;
private OffsetDateTime createdOn;
private OffsetDateTime validUntil;
private List<Permission> permissions;

public Policy update(final OffsetDateTime validUntil) {
this.validUntil = validUntil;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/********************************************************************************
* Copyright (c) 2021,2022,2023
* 2022: ZF Friedrichshafen AG
* 2022: ISTOS GmbH
* 2022,2023: Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
* 2022,2023: BOSCH AG
* Copyright (c) 2021,2022,2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
package org.eclipse.tractusx.irs.policystore.models;

/**
* A PolicyType object use in Permission
*/
public enum PolicyType {

ACCESS, USE

}
Loading

0 comments on commit 0da8794

Please sign in to comment.