Why are only two values returned why in the wrong order? #92
-
Hi :) Please see: The rr_set contains 3 values, but only 2 are returned. Why is the order not preserved? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 5 replies
-
That's just the characteristics of the set data type (unordered, unique items). This often maps well to the policy domain, where you have things like roles and permissions, and duplicates rarely make sense (e.g. what's the meaning of having two roles named If that's not what you want, you would instead use arrays. Rego doesn't have "array generating rules" like the rule generating a set in your example, but you could use an array comprehension to create an array out of items from the rr_array := [y | x := input.rr_sets[_]
y := {"name": x.name}] |
Beta Was this translation helpful? Give feedback.
-
What would be the complete rule? |
Beta Was this translation helpful? Give feedback.
-
thats strange/unexpected: package pektin_policy
default api_method=false
default ip=false
default utc_millis=false
default user_agent=false
default return_policy_results=false
rr_sets=rr_array{
rr_array := [y | rr_set := input.rr_sets[_]
y := {
"name": false, // HERE
"rr_type": true,
"ttl": true,
"value":true
}
]
}
rr_name(name) {
startswith(name,"_acme-challenge.")
endswith(name,".")
}
it returns 3 array values but when using the function rr_name that returns a boolean: package pektin_policy
default api_method=false
default ip=false
default utc_millis=false
default user_agent=false
default return_policy_results=false
rr_sets=rr_array{
rr_array := [y | rr_set := input.rr_sets[_]
y := {
"name": rr_name(rr_set.name),
"rr_type": true,
"ttl": true,
"value":true
}
]
}
rr_name(name) {
startswith(name,"_acme-challenge.")
endswith(name,".")
}
it only returns two elements with a not matching name this cannot be intended |
Beta Was this translation helpful? Give feedback.
-
this is the final result: |
Beta Was this translation helpful? Give feedback.
That's just the characteristics of the set data type (unordered, unique items). This often maps well to the policy domain, where you have things like roles and permissions, and duplicates rarely make sense (e.g. what's the meaning of having two roles named
admin
?) and order is normally not important.If that's not what you want, you would instead use arrays. Rego doesn't have "array generating rules" like the rule generating a set in your example, but you could use an array comprehension to create an array out of items from the
input
: