custom-has-key-construct
Summary: Custom function may be replaced by in
and object.keys
Category: Idiomatic
Avoid
package policy
mfa if has_key(input.claims, "mfa")
has_key(map, key) if {
_ = map[key]
}
Prefer
package policy
mfa if "mfa" in object.keys(input.claims)
Rationale
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.
Configuration Options
This linter rule provides the following configuration options:
rules:
idiomatic:
custom-has-key-construct:
# one of "error", "warning", "ignore"
level: error
Related Resources
- GitHub: Source Code