Skip to content

Early Exit In Rule Evaluations With http.send #511

Discussion options

You must be logged in to vote

Hi Brian! 👋

I assumed that as these are complete document rules that once the first rule matches the second rule either wouldn't be evaluated or the call would be cancelled/ignored.

There isn't really a first rule, as OPA may evaluate rules in any order. I you need to control the order of evaluation, you'd commonly use else for that purpose:

allow {
  input.token
  data.common.user.userOwnsToken(input.token, input.pathParameters.userId[0])
} else {
  input.token
  userData := data.common.user.getUserData
  userData.userRoles[_] == "admin"
}

Perhaps you'll find my blog on the details of expressing OR in Rego, and control flow in general, useful.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by briancullen
Comment options

You must be logged in to vote
1 reply
@anderseknert
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants