Skip to content

Commit

Permalink
policy: fixup simple default policy
Browse files Browse the repository at this point in the history
The OPA linter seems to have updated and now complains if we don't use
an if before our blocks.

This is unrelated to the rest of this PR.

Signed-off-by: Tobin Feldman-Fitzthum <[email protected]>
  • Loading branch information
fitzthum committed Dec 20, 2024
1 parent 8ffcff3 commit ce92336
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions attestation-service/src/token/simple_default_policy.rego
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@
package policy

import future.keywords.every
import future.keywords.if

default allow = false
default allow := false

allow {
allow if {
every k, v in input {
# `judge_field`: Traverse each key value pair in the input and make policy judgments on it.
#
Expand All @@ -44,7 +45,7 @@ allow {
}
}

judge_field(input_key, input_value) {
judge_field(input_key, input_value) if {
has_key(data.reference, input_key)
reference_value := data.reference[input_key]

Expand All @@ -57,16 +58,16 @@ judge_field(input_key, input_value) {
match_value(reference_value, input_value)
}

judge_field(input_key, input_value) {
judge_field(input_key, input_value) if {
not has_key(data.reference, input_key)
}

match_value(reference_value, input_value) {
match_value(reference_value, input_value) if {
not is_array(reference_value)
input_value == reference_value
}

match_value(reference_value, input_value) {
match_value(reference_value, input_value) if {
is_array(reference_value)

# `array_include`: judge the input value with the values in the array.
Expand All @@ -78,16 +79,16 @@ match_value(reference_value, input_value) {
array_include(reference_value, input_value)
}

array_include(reference_value_array, input_value) {
array_include(reference_value_array, input_value) if {
reference_value_array == []
}

array_include(reference_value_array, input_value) {
array_include(reference_value_array, input_value) if {
reference_value_array != []
some i
reference_value_array[i] == input_value
}

has_key(m, k) {
has_key(m, k) if {
_ = m[k]
}

0 comments on commit ce92336

Please sign in to comment.