Skip to content

Commit 0b3396d

Browse files
authored
Merge pull request #2281 from simonbaird/prep-test-rego-for-opa-1.0
Use consistent rego syntax in prep for opa 1.0
2 parents 09ae621 + 84a7641 commit 0b3396d

33 files changed

+196
-134
lines changed

acceptance/examples/allow_all.rego

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# Simplest never-failing policy
22
package main
33

4+
import rego.v1
5+
46
allow := []

acceptance/examples/disallowed_functions.rego

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
# test that certain rego functions are not allowed.
77
package policy.capabilities
88

9-
import future.keywords.contains
10-
import future.keywords.if
9+
import rego.v1
1110

1211
# METADATA
1312
# title: use env var
+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package main
22

3-
deny[result] {
3+
import rego.v1
4+
5+
deny contains result if {
46
result := sprintf("Failure due to %s", [data.rule_data.banana_fail_reason])
57
}

acceptance/examples/fetch_blob.rego

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package blobby
22

3-
import future.keywords.contains
4-
import future.keywords.if
5-
import future.keywords.in
3+
import rego.v1
64

75
# METADATA
86
# custom:
@@ -27,7 +25,7 @@ deny contains result if {
2725
}
2826
}
2927

30-
uri := value {
28+
uri := value if {
3129
# Assume the blob is on the same repo as the image
3230
repo := split(input.image.ref, "@")[0]
3331
# The digest of the word "spam"

acceptance/examples/filtering.rego

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
# showcase the filtering logic with include/exclude/collection.
77
package policy.filtering
88

9-
import future.keywords.contains
10-
import future.keywords.if
11-
import future.keywords.in
9+
import rego.v1
1210

1311
# METADATA
1412
# title: always pass

acceptance/examples/future_deny.rego

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package main
22

3-
deny[{"msg": result, "effective_on": effective_on}] {
4-
result := "Fails in 2099"
3+
import rego.v1
4+
5+
deny contains {"msg": result, "effective_on": effective_on} if {
6+
result := "Fails in 2099"
57
effective_on := "2099-01-01T00:00:00Z"
68
}

acceptance/examples/gloomy_day.rego

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
# Provide one always passing rule and one always failing rule
22
package gloomy
33

4+
import rego.v1
5+
46
# METADATA
57
# title: Allow gloomy rule
68
# description: This rule will never fail
79
# custom:
810
# short_name: happy
911
# failure_msg: Always succeeds
10-
deny[result] {
12+
deny contains result if {
1113
false
1214
result := "Never fails"
1315
}
@@ -18,7 +20,7 @@ deny[result] {
1820
# custom:
1921
# short_name: sad
2022
# failure_msg: Always fails
21-
deny[result] {
23+
deny contains result if {
2224
result := {
2325
"code": "gloomy.sad",
2426
"effective_on": "2022-01-01T00:00:00Z",

acceptance/examples/happy_day.rego

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Simplest never-failing policy
22
package main
33

4+
import rego.v1
5+
46
# METADATA
57
# title: Allow rule
68
# description: This rule will never fail
@@ -10,7 +12,7 @@ package main
1012
# solution: Easy
1113
# collections:
1214
# - A
13-
deny[result] {
15+
deny contains result if {
1416
false
1517
result := "Never denies"
1618
}

acceptance/examples/image_config.rego

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
# Verify image config data from input.
22
package image_config
33

4-
import future.keywords.contains
5-
import future.keywords.if
6-
import future.keywords.in
4+
import rego.v1
75

86
# METADATA
97
# title: Image Title Label
108
# description: Check if the image has the org.opencontainers.image.title label set.
119
# custom:
1210
# short_name: image_title_set
1311
# failure_msg: Missing image title label
14-
deny contains err(rego.metadata.rule()) {
12+
deny contains err(rego.metadata.rule()) if {
1513
not input.image.config.Labels["org.opencontainers.image.title"]
1614
}
1715

@@ -21,7 +19,7 @@ deny contains err(rego.metadata.rule()) {
2119
# custom:
2220
# short_name: parent_image_title_set
2321
# failure_msg: Missing parent image title label
24-
deny contains err(rego.metadata.rule()) {
22+
deny contains err(rego.metadata.rule()) if {
2523
not input.image.parent.config.Labels["org.opencontainers.image.title"]
2624
}
2725

@@ -33,7 +31,7 @@ deny contains err(rego.metadata.rule()) {
3331
# custom:
3432
# short_name: image_distinct_title_set
3533
# failure_msg: Image does not have a distinct title
36-
deny contains err(rego.metadata.rule()) {
34+
deny contains err(rego.metadata.rule()) if {
3735
l1 := input.image.config.Labels["org.opencontainers.image.title"]
3836
l2 := input.image.parent.config.Labels["org.opencontainers.image.title"]
3937
l1 == l2

acceptance/examples/keyless.rego

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package keyless
22

3-
import future.keywords.contains
4-
import future.keywords.if
5-
import future.keywords.in
3+
import rego.v1
64

75
# METADATA
86
# custom:

acceptance/examples/oci_image_files.rego

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package files
22

33
import rego.v1
44

5-
65
# METADATA
76
# custom:
87
# short_name: match

acceptance/examples/olm_manifests.rego

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package olm_manifests
22

3-
import future.keywords.contains
4-
import future.keywords.if
5-
import future.keywords.in
3+
import rego.v1
64

75
# METADATA
86
# title: Manifests are there
+3-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package pipeline.main
22

3+
import rego.v1
4+
35
expected_kind := "Pipeline"
46

57
# METADATA
68
# title: Pipeline kind is expected
79
# description: Check that the pipeline is a kind of "Pipeline"
810
# custom:
911
# short_name: expected_kind
10-
deny[result] {
12+
deny contains result if {
1113
expected_kind != input.kind
1214
result := "invalid kind"
1315
}

acceptance/examples/purl.rego

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package purl
22

3-
import future.keywords.contains
4-
import future.keywords.if
5-
import future.keywords.in
3+
import rego.v1
64

75
# METADATA
86
# custom:

acceptance/examples/reject.rego

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
# Simplest always-failing policy
22
package main
33

4-
import future.keywords.contains
5-
import future.keywords.if
6-
import future.keywords.in
4+
import rego.v1
75

86
# METADATA
97
# title: Reject rule

acceptance/examples/rules_with_dependencies.rego

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package pkg
22

3-
import future.keywords.contains
4-
import future.keywords.if
3+
import rego.v1
54

65
# METADATA
76
# custom:

acceptance/examples/trace_debug.rego

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package main
22

3-
import future.keywords.contains
4-
import future.keywords.if
3+
import rego.v1
54

65
# METADATA
76
# title: Debug

acceptance/examples/unsupported.rego

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package unsupported
22

3-
deny {
3+
import rego.v1
4+
5+
deny if {
46
true
57
}

acceptance/examples/warn.rego

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Simplest always-warning policy
22
package main
33

4-
warn[result] {
4+
import rego.v1
5+
6+
warn contains result if {
57
result := "Has a warning"
68
}
+3-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package policy.release.kitty
22

3+
import rego.v1
4+
35
# METADATA
46
# title: Kittens
57
# description: Fluffy
68
# custom:
79
# short_name: purr
810
#
9-
deny[result] {
11+
deny contains result if {
1012
result := "Meow"
1113
}

docs/policy/release/attestation.rego

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#
99
package policy.release.builtin.attestation
1010

11+
import rego.v1
12+
1113
# METADATA
1214
# title: Attestation signature
1315
# description: >-
@@ -23,7 +25,7 @@ package policy.release.builtin.attestation
2325
# collections:
2426
# - builtin
2527
#
26-
deny {
28+
deny if {
2729
false # Here just to provide documentation
2830
}
2931

@@ -40,6 +42,6 @@ deny {
4042
# collections:
4143
# - builtin
4244
#
43-
deny {
45+
deny if {
4446
false # Here just to provide documentation
4547
}

docs/policy/release/image.rego

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#
99
package policy.release.builtin.image
1010

11+
import rego.v1
12+
1113
# METADATA
1214
# title: Image signature
1315
# description: >-
@@ -23,6 +25,6 @@ package policy.release.builtin.image
2325
# collections:
2426
# - builtin
2527
#
26-
deny {
28+
deny if {
2729
false # Here just to provide documentation
2830
}

features/__snapshots__/inspect_policy.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Error: Merge error. The 'rule_data' key was found more than once!
2222
},
2323
"location": {
2424
"file": "main.rego",
25-
"row": 9,
25+
"row": 11,
2626
"col": 1
2727
},
2828
"path": [
@@ -94,7 +94,7 @@ kitty.purr
9494
---
9595

9696
[sources from ECP:stdout - 1]
97-
# Source: git::${GITHOST}/git/policy1.git?ref=8288b21ca5e7d8863efffb47c2bc3eac1274d1ff
97+
# Source: git::${GITHOST}/git/policy1.git?ref=5c216ecae44c9bd76cca3e6cce95892289a07db0
9898

9999
policy.release.kitty.purr (deny)
100100
https://enterprisecontract.dev/docs/ec-policies/release_policy.html#kitty__purr

0 commit comments

Comments
 (0)