How to call the custom function defined inside another rego #472
-
Need help, I want to reference different rego files in main.rego based on input.name. Then call custom functions defined inside that rego file but getting errors during compilation "rego_compile_error: called function policy.test shadowed". main.rego package play
import data.play.policies
allow {
policy := policies[input.name]
policy.test(input.params)
} policy1.rego package play.policies.policy1
test(params) {
params["env"] == "dev"
} policy2.rego package play.policies.policy2
test(params) {
params["env"] == "prod"
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
In package play
import data.play.policies
allow {
policy := policies[input.name].test(input.params)
} Before, this is what happened: When you do policy := policies[input.name] you'll have OPA evaluate the full extent of However, the dynamic dispatch thing you want it entirely possible, and that's what should happen in the altered snippet above. |
Beta Was this translation helpful? Give feedback.
Hmm, how about using
with
? https://play.openpolicyagent.org/p/wMu6dvXFUv