Skip to content

Commit

Permalink
Use consistent rego syntax in prep for opa 1.0
Browse files Browse the repository at this point in the history
The idea here is that once we update to opa 1.0 we'll need to always
use the new `deny contains foo if` syntax. This change is supposed
to make it easier by using that syntax consistently now.

It requires importing `rego.v1` everywhere, but we do that
consistently for all the rego in ec-policies, so let's also do it
here also.

See also #2274 which I'd like to rebase on this once it's merged.
  • Loading branch information
simonbaird committed Jan 21, 2025
1 parent 0749535 commit 473f065
Show file tree
Hide file tree
Showing 30 changed files with 180 additions and 118 deletions.
2 changes: 2 additions & 0 deletions acceptance/examples/allow_all.rego
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Simplest never-failing policy
package main

import rego.v1

allow := []
3 changes: 1 addition & 2 deletions acceptance/examples/disallowed_functions.rego
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
# test that certain rego functions are not allowed.
package policy.capabilities

import future.keywords.contains
import future.keywords.if
import rego.v1

# METADATA
# title: use env var
Expand Down
4 changes: 3 additions & 1 deletion acceptance/examples/fail_with_data.rego
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package main

deny[result] {
import rego.v1

deny contains result if {
result := sprintf("Failure due to %s", [data.rule_data.banana_fail_reason])
}
4 changes: 1 addition & 3 deletions acceptance/examples/fetch_blob.rego
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package blobby

import future.keywords.contains
import future.keywords.if
import future.keywords.in
import rego.v1

# METADATA
# custom:
Expand Down
4 changes: 1 addition & 3 deletions acceptance/examples/filtering.rego
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
# showcase the filtering logic with include/exclude/collection.
package policy.filtering

import future.keywords.contains
import future.keywords.if
import future.keywords.in
import rego.v1

# METADATA
# title: always pass
Expand Down
6 changes: 4 additions & 2 deletions acceptance/examples/future_deny.rego
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main

deny[{"msg": result, "effective_on": effective_on}] {
result := "Fails in 2099"
import rego.v1

deny contains {"msg": result, "effective_on": effective_on} if {
result := "Fails in 2099"
effective_on := "2099-01-01T00:00:00Z"
}
6 changes: 4 additions & 2 deletions acceptance/examples/gloomy_day.rego
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# Provide one always passing rule and one always failing rule
package gloomy

import rego.v1

# METADATA
# title: Allow gloomy rule
# description: This rule will never fail
# custom:
# short_name: happy
# failure_msg: Always succeeds
deny[result] {
deny contains result if {
false
result := "Never fails"
}
Expand All @@ -18,7 +20,7 @@ deny[result] {
# custom:
# short_name: sad
# failure_msg: Always fails
deny[result] {
deny contains result if {
result := {
"code": "gloomy.sad",
"effective_on": "2022-01-01T00:00:00Z",
Expand Down
4 changes: 3 additions & 1 deletion acceptance/examples/happy_day.rego
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Simplest never-failing policy
package main

import rego.v1

# METADATA
# title: Allow rule
# description: This rule will never fail
Expand All @@ -10,7 +12,7 @@ package main
# solution: Easy
# collections:
# - A
deny[result] {
deny contains result if {
false
result := "Never denies"
}
10 changes: 4 additions & 6 deletions acceptance/examples/image_config.rego
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
# Verify image config data from input.
package image_config

import future.keywords.contains
import future.keywords.if
import future.keywords.in
import rego.v1

# METADATA
# title: Image Title Label
# description: Check if the image has the org.opencontainers.image.title label set.
# custom:
# short_name: image_title_set
# failure_msg: Missing image title label
deny contains err(rego.metadata.rule()) {
deny contains err(rego.metadata.rule()) if {
not input.image.config.Labels["org.opencontainers.image.title"]
}

Expand All @@ -21,7 +19,7 @@ deny contains err(rego.metadata.rule()) {
# custom:
# short_name: parent_image_title_set
# failure_msg: Missing parent image title label
deny contains err(rego.metadata.rule()) {
deny contains err(rego.metadata.rule()) if {
not input.image.parent.config.Labels["org.opencontainers.image.title"]
}

Expand All @@ -33,7 +31,7 @@ deny contains err(rego.metadata.rule()) {
# custom:
# short_name: image_distinct_title_set
# failure_msg: Image does not have a distinct title
deny contains err(rego.metadata.rule()) {
deny contains err(rego.metadata.rule()) if {
l1 := input.image.config.Labels["org.opencontainers.image.title"]
l2 := input.image.parent.config.Labels["org.opencontainers.image.title"]
l1 == l2
Expand Down
4 changes: 1 addition & 3 deletions acceptance/examples/keyless.rego
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package keyless

import future.keywords.contains
import future.keywords.if
import future.keywords.in
import rego.v1

# METADATA
# custom:
Expand Down
1 change: 0 additions & 1 deletion acceptance/examples/oci_image_files.rego
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package files

import rego.v1


# METADATA
# custom:
# short_name: match
Expand Down
4 changes: 1 addition & 3 deletions acceptance/examples/olm_manifests.rego
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package olm_manifests

import future.keywords.contains
import future.keywords.if
import future.keywords.in
import rego.v1

# METADATA
# title: Manifests are there
Expand Down
4 changes: 3 additions & 1 deletion acceptance/examples/pipeline_basic.rego
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package pipeline.main

import rego.v1

expected_kind := "Pipeline"

# METADATA
# title: Pipeline kind is expected
# description: Check that the pipeline is a kind of "Pipeline"
# custom:
# short_name: expected_kind
deny[result] {
deny contains result if {
expected_kind != input.kind
result := "invalid kind"
}
4 changes: 1 addition & 3 deletions acceptance/examples/purl.rego
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package purl

import future.keywords.contains
import future.keywords.if
import future.keywords.in
import rego.v1

# METADATA
# custom:
Expand Down
4 changes: 1 addition & 3 deletions acceptance/examples/reject.rego
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# Simplest always-failing policy
package main

import future.keywords.contains
import future.keywords.if
import future.keywords.in
import rego.v1

# METADATA
# title: Reject rule
Expand Down
3 changes: 1 addition & 2 deletions acceptance/examples/rules_with_dependencies.rego
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package pkg

import future.keywords.contains
import future.keywords.if
import rego.v1

# METADATA
# custom:
Expand Down
3 changes: 1 addition & 2 deletions acceptance/examples/trace_debug.rego
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import future.keywords.contains
import future.keywords.if
import rego.v1

# METADATA
# title: Debug
Expand Down
4 changes: 3 additions & 1 deletion acceptance/examples/unsupported.rego
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package unsupported

deny {
import rego.v1

deny if {
true
}
4 changes: 3 additions & 1 deletion acceptance/examples/warn.rego
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Simplest always-warning policy
package main

warn[result] {
import rego.v1

warn contains result if {
result := "Has a warning"
}
4 changes: 3 additions & 1 deletion acceptance/examples/with_annotations.rego
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package policy.release.kitty

import rego.v1

# METADATA
# title: Kittens
# description: Fluffy
# custom:
# short_name: purr
#
deny[result] {
deny contains result if {
result := "Meow"
}
6 changes: 4 additions & 2 deletions docs/policy/release/attestation.rego
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#
package policy.release.builtin.attestation

import rego.v1

# METADATA
# title: Attestation signature
# description: >-
Expand All @@ -23,7 +25,7 @@ package policy.release.builtin.attestation
# collections:
# - builtin
#
deny {
deny if {
false # Here just to provide documentation
}

Expand All @@ -40,6 +42,6 @@ deny {
# collections:
# - builtin
#
deny {
deny if {
false # Here just to provide documentation
}
4 changes: 3 additions & 1 deletion docs/policy/release/image.rego
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#
package policy.release.builtin.image

import rego.v1

# METADATA
# title: Image signature
# description: >-
Expand All @@ -23,6 +25,6 @@ package policy.release.builtin.image
# collections:
# - builtin
#
deny {
deny if {
false # Here just to provide documentation
}
8 changes: 5 additions & 3 deletions internal/evaluator/__testdir__/simple/a.rego
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# A set of policies
package a

import rego.v1

# METADATA
# title: Failure
# description: Failure description.
# custom:
# short_name: failure
deny[result] {
deny contains result if {
result := {
"code": "a.failure",
"msg": "Failure!",
Expand All @@ -17,7 +19,7 @@ deny[result] {
# description: Warning description.
# custom:
# short_name: warning
warn[result] {
warn contains result if {
result := {
"code": "a.warning",
"msg": "Warning!",
Expand All @@ -28,7 +30,7 @@ warn[result] {
# description: Success description.
# custom:
# short_name: success
deny[result] {
deny contains result if {
false
result := "Success!"
}
8 changes: 5 additions & 3 deletions internal/evaluator/__testdir__/simple/b.rego
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# B set of policies
package b

import rego.v1

# METADATA
# custom:
# short_name: failure
deny[result] {
deny contains result if {
result := {
"code": "b.failure",
"msg": "Failure!",
Expand All @@ -13,7 +15,7 @@ deny[result] {
# METADATA
# custom:
# short_name: warning
warn[result] {
warn contains result if {
result := {
"code": "b.warning",
"msg": "Warning!",
Expand All @@ -22,7 +24,7 @@ warn[result] {
# METADATA
# custom:
# short_name: success
deny[result] {
deny contains result if {
false
result := "Success!"
}
4 changes: 3 additions & 1 deletion internal/evaluator/__testdir__/unconforming/no_msg.rego
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package no_msg

deny {
import rego.v1

deny if {
true
}
Loading

0 comments on commit 473f065

Please sign in to comment.