Define multiple rules #66
-
I have a use-case where I need to implement multiple rules in the Rego file to validate GET, POST endpoints with different x-incoming-flow custom header. For example in the example below; my intension is to allow HR applications (indicated by request hr-flow) to retrieve basic demographic information. Similarly allow finance applications (indicated by finance-flow) to update finance information. The headers are passed by consuming applications. In this use-case, what is the best practice to prepare the rules? Do I need to write multiple allow blocks or is there a better way to write them in a single allow block. Please advise
Input 1: -- Output should be true
Input 2: -- Output should be false
Input 3: -- Output should be true
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi @gituserjava 👋 Yes, the way you've done it with multiple allow rules is the idiomatic way of doing it. If there are a lot of lines being repeated you could move those to a separate helper rule, but in your case it seems the conditions are unique for each allow rule, so that's the best way of doing it. |
Beta Was this translation helpful? Give feedback.
Hi @gituserjava 👋
Yes, the way you've done it with multiple allow rules is the idiomatic way of doing it. If there are a lot of lines being repeated you could move those to a separate helper rule, but in your case it seems the conditions are unique for each allow rule, so that's the best way of doing it.