Skip to content

Commit 5b7a971

Browse files
added training
Signed-off-by: ivan katliarchuk <[email protected]>
1 parent c34c2cf commit 5b7a971

File tree

6 files changed

+99
-0
lines changed

6 files changed

+99
-0
lines changed

playground/ex22/input.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"items": [
3+
{
4+
"id": "1bd91655",
5+
"name": "Lunch with James",
6+
"amount": 57.5
7+
},
8+
{
9+
"id": "226c3910",
10+
"name": "Flight to Berlin",
11+
"amount": 389.78,
12+
"category": "conferences"
13+
},
14+
{
15+
"id": "db5a4b23",
16+
"name": "Recurring SaaS Subscription",
17+
"amount": 30,
18+
"category": "saas",
19+
"approved_by": "90400852"
20+
}
21+
]
22+
}

playground/ex22/policy.rego

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package play
2+
3+
# https://docs.styra.com/opa/rego-by-example/keywords/contains
4+
5+
import rego.v1
6+
7+
approval_min := 350
8+
9+
reasons[item.id] contains "category must be set" if {
10+
some item in input.items
11+
12+
object.get(item, "category", "") == ""
13+
}
14+
15+
reasons[item.id] contains message if {
16+
some item in input.items
17+
18+
item.amount > approval_min
19+
20+
object.get(item, "approved_by", "") == ""
21+
22+
message := sprintf(
23+
"items over %d must be approved",
24+
[approval_min],
25+
)
26+
}
27+
28+
reasons[item.id] contains "approver does not exist" if {
29+
some item in input.items
30+
31+
not data.approvers[item.approved_by]
32+
}

playground/ex23/first.rego

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package package1
2+
3+
import rego.v1
4+
5+
name := "World"

playground/ex23/second.rego

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package package2
2+
3+
import rego.v1
4+
5+
import data.package1
6+
7+
output := sprintf("Hello, %v", [package1.name])
8+
9+
# or
10+
import data.package1 as p1
11+
12+
output := sprintf("Hello, %v", [p1.name])

playground/ex24/policy.rego

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package play
2+
3+
import rego.v1
4+
# https://docs.styra.com/opa/rego-by-example/keywords/some
5+
example_array := [1, "example", 3]
6+
7+
filtered_array := [e |
8+
some e in example_array
9+
10+
is_number(e)
11+
]

playground/ex25/policy.rego

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package play
2+
3+
# https://docs.styra.com/opa/rego-by-example/keywords/some
4+
import rego.v1
5+
6+
example_object := {
7+
"read": true,
8+
"write": true,
9+
"delete": false,
10+
"create": false,
11+
}
12+
13+
permission_list contains permission if {
14+
some permission, value in example_object
15+
16+
value == true
17+
}

0 commit comments

Comments
 (0)