Dynamic policy with optional input fields #670
-
Looking for some guidance on how to achieve to following: I have an input that will have 2 fields from 4 possibles (id, name, phone and code). So, my input would be have (id, name) or (id, phone) or (id, code), and so on. To add more fun to it, I am also using dynamic policies, so basically I have something like this:
If I send the input:
I get result := false while I would like to get result:= true. I know that I could achieve that by creating all pair combinations for the result rule but that sounds extremely redundant. Any idea on how to achieve my objective? So far the best solution that I found is to use add "default" values for the inexistent fields using object.get as in:
Is this the way to go or am I missing a better way to do it? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
How about something like
The test for each input becomes clear, as well as which combinations are valid. |
Beta Was this translation helpful? Give feedback.
-
Maybe I missed something, but why reconstruct result := true if {
my_single_policy_from_another_file with input as {
"name": input.name,
"id": input.id,
"code": input.code,
"phone": input.phone
}
} Is really just a more fragile (as you've noticed) way to express this: result if {
my_single_policy_from_another_file
} Now if you for some reason really need to define a new object from input that has the same defined/undefined properties (perhaps with some added variations), you could build an incremental object rule and use that: obj["id"] := input.id
obj["name"] := input.name
obj["code"] := input.code
obj["phone"] := input.phone
result if {
my_single_policy_from_another_file with input as obj
} |
Beta Was this translation helpful? Give feedback.
Maybe I missed something, but why reconstruct
input
with identical fields from the actualinput
? Theinput
object is global and can be read from any policy. This:Is really just a more fragile (as you've noticed) way to express this:
result if { my_single_policy_from_another_file }
Now if you for some reason really need to define a new object from input that has the same defined/undefined properties (perhaps with some added variations), you could build an incremental object rule and use that:
obj["…