Code from github.com/anakrish/rego-rs

Authored by anakrish and mingweishih

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
This commit is contained in:
Anand Krishnamoorthi
2023-02-09 10:56:54 -08:00
parent 8f67aeecb0
commit cb0b3a1790
85 changed files with 11144 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
# Copyright (c) Rego-Rs Authors.
# Licensed under the Apache 2.0 license.
cases:
- note: same-line-no-body
rego: |
package test
add(x, y) := 5 sub(x, y) = 5
package: --skip--
imports:
policy:
- spec:
span: add(x, y) := 5
head:
func:
span: add(x, y) := 5
refr:
var: add
args:
- var: x
- var: y
assign:
span: := 5
op: :=
value:
number: 5
bodies: []
- spec:
span: sub(x, y) = 5
head:
func:
span: sub(x, y) = 5
refr:
var: sub
args:
- var: x
- var: y
assign:
span: = 5
op: =
value:
number: 5
bodies: []
+250
View File
@@ -0,0 +1,250 @@
# Copyright (c) Rego-Rs Authors.
# Licensed under the Apache 2.0 license.
cases:
- note: no-query
rego: |
package test
x = 10 else {
true
}
error: unexpected keyword `else`
- note: no-query
rego: |
package test
x = 10 {
false
} {
true
}
policy:
- spec:
head:
compr:
refr:
var: x
assign:
op: "="
value:
number: 10
bodies:
- query:
stmts:
- literal:
expr:
false
- query:
stmts:
- literal:
expr:
true
- note: no-else
rego: |
package test
x = 10 {
false
} {
true
}
policy:
- spec:
head:
compr:
refr:
var: x
assign:
op: "="
value:
number: 10
bodies:
- query:
stmts:
- literal:
expr:
false
- query:
stmts:
- literal:
expr:
true
- note: if-no-else
rego: |
package test
import future.keywords.if
x = 10 if {
false
} {
true
}
policy:
- spec:
head:
compr:
refr:
var: x
assign:
op: "="
value:
number: 10
bodies:
- query:
stmts:
- literal:
expr:
false
- query:
stmts:
- literal:
expr:
true
- note: rule-named-if
rego: |
package test
x = 10 if {
false
} {
true
}
policy:
- spec:
head:
compr:
refr:
var: x
assign:
op: "="
value:
number: 10
bodies: []
- spec:
head:
compr:
refr:
var: if
bodies:
- query:
stmts:
- literal:
expr:
false
- query:
stmts:
- literal:
expr:
true
- note: query-else
rego: |
package test
x = 10 {
false
} else {
true
}
policy:
- spec:
head:
compr:
refr:
var: x
assign:
op: "="
value:
number: 10
bodies:
- query:
stmts:
- literal:
expr:
false
- query:
stmts:
- literal:
expr:
true
- note: if-literal-else
rego: |
package test
import future.keywords.if
x = 10 if 1 < 0 else {
true
}
policy:
- spec:
head:
compr:
refr:
var: x
assign:
op: "="
value:
number: 10
bodies:
- query:
stmts:
- literal:
expr:
boolexpr:
op: "<"
lhs:
number: 1
rhs:
number: 0
- query:
stmts:
- literal:
expr:
true
- note: if-literal-else-assign
rego: |
package test
import future.keywords.if
# This will evaluate to 10
x = 10 if 1 < 0 else := 20 {
true
}
policy:
- spec:
head:
compr:
refr:
var: x
assign:
op: "="
value:
number: 10
bodies:
- query:
stmts:
- literal:
expr:
boolexpr:
op: "<"
lhs:
number: 1
rhs:
number: 0
- assign:
op: ":="
value:
number: 20
query:
stmts:
- literal:
expr:
true
+135
View File
@@ -0,0 +1,135 @@
# Copyright (c) Rego-Rs Authors.
# Licensed under the Apache 2.0 license.
cases:
- note: contains
rego: |
package test
import future.keywords
deny.a contains 0, "bar" in ["bar1"] if true
policy:
- spec:
head:
set:
refr:
refdot:
refr:
var: deny
field: a
key:
inexpr:
key:
number: 0
value:
string: bar
collection:
array:
- string: bar1
bodies:
- query:
stmts:
- literal:
expr:
true
- note: old-syntax
rego: |
package test
import future.keywords.if
# The following are not sets
x1 if true
x2 { true }
# The following are sets
y.a { true }
y["b"] { true }
# The following are not sets
z.a if { true }
z["b"] if { true }
policy:
- spec:
head:
compr:
refr:
var: x1
bodies:
- query:
stmts:
- literal:
expr:
true
- spec:
head:
compr:
refr:
var: x2
bodies:
- query:
stmts:
- literal:
expr:
true
- spec:
head:
set:
refr:
refdot:
refr:
var: y
field: a
bodies:
- query:
stmts:
- literal:
expr:
true
- spec:
head:
set:
refr:
var: y
key:
string: b
bodies:
- query:
stmts:
- literal:
expr:
true
- spec:
head:
compr:
refr:
refdot:
refr:
var: z
field: a
bodies:
- query:
stmts:
- literal:
expr:
true
- spec:
head:
compr:
refr:
refbrack:
refr:
var: z
index:
string: b
bodies:
- query:
stmts:
- literal:
expr:
true