How to extract key1 OR key2 from an object? #404
-
Hi all, I can't figure out how to do a simple task.
Now, input can contain ONLY ONE of: "x-amzn-oidc-data" or "authorization", and I need to extract it. So, I need a REGO function that is equivalent of this python code: def get_token(input_):
for key, value in input_["attributes"]["request"]["http"]["headers"].items():
if key == "x-amzn-oidc-data":
return value
if key == "authorization":
return value[7:] Can someone help me with this? Best regards, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hey Ivan, how about this: jwt_token := input.attributes.request.http.headers["x-amzn-oidc-data"]
jwt_token := input.attributes.request.http.headers.authorization It's a complete rule You would run into trouble if both headers could be present, since complete rules may only evaluate to one value. If both were possible, you'd need to decide some precedence rule and encode that in your rule bodies, like jwt_token := input.attributes.request.http.headers.authorization
jwt_token := input.attributes.request.http.headers["x-amzn-oidc-data"] if not input.attributes.request.http.headers.authorization ☝️ This would give "authorization" precedence over "x-amzn-oidc-data" (and it's using |
Beta Was this translation helpful? Give feedback.
Hey Ivan,
how about this:
It's a complete rule
jwt_token
, and it'll either evaluate to the value of the one header, if present; or the other header, if present; or it'll be undefined.You would run into trouble if both headers could be present, since complete rules may only evaluate to one value. If both were possible, you'd need to decide some precedence rule and encode that in your rule bodies, like