defer-assignment
Summary: Assignment can be deferred
Category: Performance
Avoid
package policy
allow if {
resp := http.send({"method": "GET", "url": "http://example.com"})
# this check does not depend on the response above
# and thus the resp := ... assignment can be deferred to
# after the check
input.user.name in allowed_users
resp.status_code == 200
# more done with response here
}
Prefer
package policy
allow if {
input.user.name in allowed_users
# the next expression *does* depend on `resp`
resp := http.send({"method": "GET", "url": "http://example.com"})
resp.status_code == 200
# more done with response here
}