Summary: Custom function may be replaced by in
and object.keys
Category: Idiomatic
Avoid
package policy
import rego.v1
mfa if has_key(input.claims, "mfa")
has_key(map, key) if {
_ = map[key]
}
Prefer
package policy
import rego.v1
mfa if "mfa" in object.keys(input.claims)
Checking if a key exists in an object (regardless of the attribute's value) used to be done using custom functions. With
the introduction of the object.keys
(OPA v0.47.0) function, this is no longer necessary,
and using the built-in function together with in
should be preferred.
This linter rule provides the following configuration options:
rules:
idiomatic:
custom-has-key-construct:
# one of "error", "warning", "ignore"
level: error
- GitHub: Source Code
If you think you've found a problem with this rule or its documentation, would like to suggest improvements, new rules,
or just talk about Regal in general, please join us in the #regal
channel in the Styra Community
Slack!