How to evaluate non-existence of a value/attribute as true #258
-
Hi, My input data is something like this { "object": { "value": "1" }} and want to have rule that will return true if "value" attribute is not present in the "object" or if its value is "1" i.e. "object.value" == "1". I tried few things but couldn't get; please refer https://play.openpolicyagent.org/p/ZIJmGRgzB3. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
I suggest you use multiple default allow = false
allow { # absent key
not has_key(data.object, "value")
}
allow { # if it's there, it's got to be "1"
data.object.value == "1"
} See also this playground |
Beta Was this translation helpful? Give feedback.
I suggest you use multiple
allow
rule bodies -- they will be implicitly OR'ed together. So something along these lines:See also this playground