Debian Codegraph @

examples/prism-rego.html

raw symbols SCIP
1 <h2>Full example</h2>
2 <pre><code># Role-based Access Control (RBAC)
3
4 # By default, deny requests.
5 default allow = false
6
7 # Allow admins to do anything.
8 allow {
9 user_is_admin
10 }
11
12 # Allow the action if the user is granted permission to perform the action.
13 allow {
14 # Find grants for the user.
15 some grant
16 user_is_granted[grant]
17
18 # Check if the grant permits the action.
19 input.action == grant.action
20 input.type == grant.type
21 }
22
23 # user_is_admin is true if...
24 user_is_admin {
25
26 # for some `i`...
27 some i
28
29 # "admin" is the `i`-th element in the user->role mappings for the identified user.
30 data.user_roles[input.user][i] == "admin"
31 }
32
33 # user_is_granted is a set of grants for the user identified in the request.
34 # The `grant` will be contained if the set `user_is_granted` for every...
35 user_is_granted[grant] {
36 some i, j
37
38 # `role` assigned an element of the user_roles for this user...
39 role := data.user_roles[input.user][i]
40
41 # `grant` assigned a single grant from the grants list for 'role'...
42 grant := data.role_grants[role][j]
43 }
44 </code></pre>