can opa team provide some code sample about using if else loop in a rule? #85
-
I try to make below code work. basically, this requires embedding a if else loop inside a rule block...but I keep getting error no matter how I tweak the code...any suggestion here? the error I got in rego playground is:
where input is:
default hello = false make_new_patch(path, value) = patchCode {
} add_new_patch(path, value) = patchCode {
} hello[patch] { |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Both package play
make_new_patch(path, value) = patchCode {
patchCode = {
"op": "make",
"path": path,
"value": value
}
}
add_new_patch(path, value) = patchCode {
patchCode = {
"op": "add",
"path": path,
"value": value,
"comment": "not make"
}
}
hello = add_new_patch("some_path", "some_value") {
input.message == "add"
} else = make_new_patch("other_path", "other_value")
|
Beta Was this translation helpful? Give feedback.
Both
add_new_patch
andmake_new_patch
are functions, but you are referencing them as if they were rules. I can't say I fully understand what you're trying to accomplish, but if you just want to make the function call conditionally, something like this would do it: