open-policy-agentrego

Using OR condition in OPA rego


I want to use an OR operation to combine the following conditions:

Currently I am using the built-in function any():

any([count(arr) != 0, not contains(email, "test.com")])

However my rule is producing an error.

How can I achieve and improve this in one line?


Solution

  • The not keyword is a bit of a special case in that it can't be used inside of many contexts such as the array of your example. I believe this could be improved in OPA, but until then you can trivially avoid it for at most cases, like the one you provided:

    any([count(arr) != 0, contains(email, "test.com") == false])