Skip to content

Commit

Permalink
Merge pull request #7 from wistefan/ngsi-ld
Browse files Browse the repository at this point in the history
tmf
  • Loading branch information
wistefan authored Jun 18, 2024
2 parents 45d5c15 + 9d5eaf0 commit 73d8646
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 17 deletions.
9 changes: 8 additions & 1 deletion doc/REGO.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
| leftOperand | dome-op:relatedParty | related_party(http_part) | get the entity from tm-forum and extract related party |
| leftOperand | dome-op:owner | owner(related_party) | filter the given list of related_party(ies) for one with role "Owner" |
| leftOperand | dome-op:relatedParty_role | related_party_role(entity) | return the role from the related party of an entity |
| leftOperand | TMF-PCMA:lifecycleStatus | life_cycle_status(entity) | return the lifeCycleStatus of a given entity |
| leftOperand | dome-op:validFor_endDateTime | valid_for_end_date_time(entity) | return the end of the validity of an entity |
| leftOperand | dome-op:validFor_startDateTime | valid_for_start_date_time(entity) | return the start of the validity of an entity |
| action | dome-op:create | is_creation(request) | Check if the given request is a creation |
Expand Down Expand Up @@ -68,6 +67,7 @@
| --- | --- | --- | --- |
| leftOperand | vc:role | role(verifiable_credential,organization_id) | retrieves the roles from the credential, that target the current organization |
| leftOperand | vc:currentParty | current_party(credential) | the current (organization)party, |
| assignee | odrl:any | is_any | allows for any user |

## ngsild

Expand All @@ -78,3 +78,10 @@
| leftOperand | ngsi-ld:<property>_observedAt | # | retrieves the observedAt of the property The method should be concretized in the mapping.json, to match a concrete property. |
| leftOperand | ngsi-ld:<property>_modifiedAt | # | retrieves the modifiedAt of the property The method should be concretized in the mapping.json, to match a concrete property. |
| leftOperand | ngsi-ld:<relationship> | # | retrieves the object of the relationship, only applies to properties of type "Relationship". The method should be concretized in the mapping.json, to match a concrete property. |

## tmf

| ODRL Class | ODRL Key | Rego-Method | Description |
| --- | --- | --- | --- |
| leftOperand | tmf:lifecycleStatus | life_cycle_status(entity) | return the lifeCycleStatus of a given entity |
| leftOperand | tmf:resource | resource_type(http_part) | retrieves the type of the resource from the path |
18 changes: 12 additions & 6 deletions src/main/resources/mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,14 @@
"regoMethod": "dome_lo.valid_for_end_date_time(helper.entity)"
}
},
"TMF-PCMA": {
"tmf": {
"lifecycleStatus": {
"regoPackage": "dome.leftOperand as dome_lo",
"regoMethod": "dome_lo.life_cycle_status(helper.entity)"
"regoPackage": "tmf.leftOperand as tmf_lo",
"regoMethod": "tmf_lo.life_cycle_status(helper.entity)"
},
"resource": {
"regoPackage": "tmf.leftOperand as tmf_lo",
"regoMethod": "tmf_lo.resource_type(helper.http_part)"
}
}
},
Expand All @@ -192,10 +196,12 @@
"assignee": {
"regoPackage": "odrl.assignee as odrl_assignee",
"regoMethod": "odrl_assignee.is_user(helper.issuer,%s)"
},
}
},
"vc": {
"any": {
"regoPackage": "odrl.assignee as odrl_assignee",
"regoMethod": "odrl_assignee.is_any"
"regoPackage": "vc.assignee as vc_assignee",
"regoMethod": "vc_assignee.is_any"
}
}
},
Expand Down
30 changes: 30 additions & 0 deletions src/main/resources/rego-resources.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,33 @@ rego/utils/kong.rego
rego/utils/apisix.rego
rego/vc/leftOperand.rego
rego/ngsi-ld/leftOperand.rego
rego/dome/leftOperand.rego
rego/dome/action.rego
rego/odrl/operand.rego
rego/odrl/rightOperand.rego
rego/odrl/operator.rego
rego/odrl/leftOperand.rego
rego/odrl/target.rego
rego/odrl/action.rego
rego/odrl/assignee.rego
rego/utils/kong.rego
rego/utils/apisix.rego
rego/vc/leftOperand.rego
rego/vc/assignee.rego
rego/ngsi-ld/leftOperand.rego
rego/tmf/leftOperand.rego
rego/dome/leftOperand.rego
rego/dome/action.rego
rego/odrl/operand.rego
rego/odrl/rightOperand.rego
rego/odrl/operator.rego
rego/odrl/leftOperand.rego
rego/odrl/target.rego
rego/odrl/action.rego
rego/odrl/assignee.rego
rego/utils/kong.rego
rego/utils/apisix.rego
rego/vc/leftOperand.rego
rego/vc/assignee.rego
rego/ngsi-ld/leftOperand.rego
rego/tmf/leftOperand.rego
4 changes: 0 additions & 4 deletions src/main/resources/rego/dome/leftOperand.rego
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ owner(related_party) := o_id if {
# return the role from the related party of an entity
related_party_role(entity) := related_party(entity).role

## TMF-PCMA:lifecycleStatus
# return the lifeCycleStatus of a given entity
life_cycle_status(entity) := entity.lifeCycleStatus

## dome-op:validFor_endDateTime
# return the end of the validity of an entity
valid_for_end_date_time(entity) := time.parse_rfc3339_ns(entity.validFor.endDataTime)
Expand Down
5 changes: 0 additions & 5 deletions src/main/resources/rego/odrl/assignee.rego
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,3 @@ import rego.v1
## odrl:uid,odrl:assignee
# is the given user id the same as the given uid
is_user(user,uid) if user == uid

## odrl:any
# allows for any user
is_any := true

20 changes: 20 additions & 0 deletions src/main/resources/rego/tmf/leftOperand.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package tmf.leftOperand

import rego.v1

## tmf:lifecycleStatus
# return the lifeCycleStatus of a given entity
life_cycle_status(entity) := entity.lifeCycleStatus

## tmf:resource
# retrieves the type of the resource from the path
resource_type(http_part) := resource if {
path_without_query := split(http_part.path, "?")[0]
path_elements := split(path_without_query, "/")
# reverse the path to get the potential id element first
reversed := array.reverse(path_elements)
# remove the (potential) id element from the path array
non_id_parts := [path_element | some path_element in reversed; not contains(path_element, "ngsi-ld")]
# after removal of the id, the resource is the first one to be retrieved
resource = non_id_parts[0]
}
7 changes: 7 additions & 0 deletions src/main/resources/rego/vc/assignee.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package vc.assignee

import rego.v1

## odrl:any
# allows for any user
is_any := true
Binary file modified src/test/resources/examples/dome/1004/1004.json
Binary file not shown.
2 changes: 1 addition & 1 deletion src/test/resources/examples/ngsi-ld/types/types.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
]
},
"odrl:assignee": {
"@id": "odrl:any"
"@id": "vc:any"
},
"odrl:action": {
"@id": "dome-op:read"
Expand Down

0 comments on commit 73d8646

Please sign in to comment.