File tree Expand file tree Collapse file tree 6 files changed +99
-0
lines changed Expand file tree Collapse file tree 6 files changed +99
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 1+ package package1
2+
3+ import rego.v1
4+
5+ name := " World"
Original file line number Diff line number Diff line change 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])
Original file line number Diff line number Diff line change 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+ ]
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments