cerbos' CEL runtime doesn't support macros? i'm tr...
# help
j
cerbos' CEL runtime doesn't support macros? i'm trying to search for a value in this array. i'm looking for a condition where "org_id" = "abc123" in that array.
Copy code
"orgs": [	
		{
			"org_id" : "xxxxxxxxxxxxxxxxxx",
			"org_name" : "xxxxxxxxxxxxxxxxx"
		},
		{
			"org_id" : "xxxxxxxxxxxxxxxxxx",
			"org_name" : "xxxxxxxxxxxxxxxxx"
		}
	]
so far i've tried
Copy code
- expr: > 
    request.aux_data.jwt.org_info.orgs.exists_one(org_id, "abc123")
and
cerbos compile
throws an error
d
Cerbos conditions do support macros.
has
,
map
,
filter
and alike are all macros. Which API are you using? Whatโ€™s your condition expression?
Please try this:
Copy code
- expr: > 
    request.aux_data.jwt.org_info.orgs.exists_one(t, t.org_id == "abc123")
j
oh my god
let me try that
i can't find any good CEL tutorials /e xamples
d
Did you know cerbos has REPL to try CEL expressions?
j
no i didn't
any docs on that?
d
j
very nice
d
Regarding CEL examples. I think this page https://docs.cerbos.dev/cerbos/latest/policies/conditions.html is a good starting point, which hopefully is enough for most Cerbos use cases. Then thereโ€™s an official intro and the language definition but the latter is quite verbose.
Did the fix work out for you?
j
yes it does
๐ŸŽ‰ 1
thank you so much
๐Ÿ‘ 1
i'll try to read up more on CEL
the language definition part is not 100% clear to me but i'll try out more experiments
d
Yes, it is quite complicated.
I think revisiting Cerbos docs page about conditions and experimenting with REPL will do the trick.
๐Ÿ’ฏ 1
No worries, Iโ€™m happy to help.
j
@Dennis (Cerbos) in a test suite, is this how i would represent the orgs structure from above?
Copy code
auxData:
    validJWT:
      jwt:
        org_info: { 
            default_org_id: "some value",
            orgs: [ 
                { org_id : "abc123" }, 
                { org_id : "def456" }
            ]
        } 
        aud: [ "my audience" ]
d
Missing comma after the last
}
. Otherwise looks good
๐Ÿ‘ 1
Oops. This is yaml. No comma
๐Ÿ˜… 1
j
everything works beautifully now. ๐Ÿฅฐ
๐ŸŽ‰ 1
so elegant. ๐Ÿ™‚
gratitude thank you
๐Ÿ™Œ 1