Skip to content

Commit

Permalink
add policies examples
Browse files Browse the repository at this point in the history
  • Loading branch information
samteb committed Jan 12, 2024
1 parent 3d711ed commit e630955
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
33 changes: 33 additions & 0 deletions apps/authz/src/app/opa/rego/lib/policies/policy1.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package main

import future.keywords.in

permit[{"policyId": "test-policy-1"}] := reason {
not is_principal_root_user
is_principal_assigned_to_wallet
check_transfer_token_type({"transferToken"})
check_transfer_token_address({"0x2791bca1f2de4661ed88a30c99a7a9449aa84174"})
check_transfer_token_operation({"operator": "lte", "value": 1000000000000000000})

approvalsRequired = [
{
"threshold": 2,
"countPrincipal": false,
"entityType": "Narval::User",
"entityIds": ["test-bob-uid", "test-bar-uid", "test-signer-uid"],
}
]

approvalsResults = [res |
approval := approvalsRequired[_]
res := check_approval(approval)
]

approvals := get_approvals_result(approvalsResults)

reason := {
"policyId": "test-policy-1",
"approvalsSatisfied": approvals.approvalsSatisfied,
"approvalsMissing": approvals.approvalsMissing,
}
}
33 changes: 33 additions & 0 deletions apps/authz/src/app/opa/rego/lib/policies/policy2.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package main

import future.keywords.in

permit[{"policyId": "test-policy-2"}] := reason {
not is_principal_root_user
is_principal_assigned_to_wallet
check_transfer_token_type({"transferToken"})
check_transfer_token_address({"0x2791bca1f2de4661ed88a30c99a7a9449aa84174"})
check_transfer_token_operation({"operator": "lte", "value": 1000000000000000000})

approvalsRequired = [
{
"threshold": 2,
"countPrincipal": false,
"entityType": "Narval::UserGroup",
"entityIds": ["test-user-group-one-uid"],
},
]

approvalsResults = [res |
approval := approvalsRequired[_]
res := check_approval(approval)
]

approvals := get_approvals_result(approvalsResults)

reason := {
"policyId": "test-policy-2",
"approvalsSatisfied": approvals.approvalsSatisfied,
"approvalsMissing": approvals.approvalsMissing,
}
}
31 changes: 31 additions & 0 deletions apps/authz/src/app/opa/rego/lib/policies/policy3.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package main

import future.keywords.in

permit[{"policyId": "test-policy-3"}] := reason {
not is_principal_root_user
is_principal_assigned_to_wallet
check_transfer_token_type({"transferToken"})
check_transfer_token_address({"0x2791bca1f2de4661ed88a30c99a7a9449aa84174"})
check_transfer_token_operation({"operator": "eq", "value": 1000000000000000000})

approvalsRequired = [{
"threshold": 2,
"countPrincipal": false,
"entityType": "Narval::UserRole",
"entityIds": ["root", "admin"],
}]

approvalsResults = [res |
approval := approvalsRequired[_]
res := check_approval(approval)
]

approvals := get_approvals_result(approvalsResults)

reason := {
"policyId": "test-policy-3",
"approvalsSatisfied": approvals.approvalsSatisfied,
"approvalsMissing": approvals.approvalsMissing,
}
}

0 comments on commit e630955

Please sign in to comment.