caveat map assertion example
# spicedb
g
I'm currently testing out caveats in the playground and stuck with writing assertions with maps. I've got following caveat (like the one in the caveat documentation):
Copy code
caveat attributes_match(expected map<any>, provided map<any>) {
    expected.isSubtreeOf(provided)
}
So how can I write the assertion to include maps?
Copy code
... with {"attributes_match": ????}
Can you give me an example? Many thanks!
e
we definitely need a few more examples of this in the docs if your schema is:
Copy code
definition platform {
    relation administrator: user with attributes_match
    permission super_admin = administrator
}
then you can write an assertion like this:
platform:demo#super_admin@user:bob with {"session": {"active": true, "iss": "google"}}
g
Thx, but somehow the assertion doesn't match the caveat?
I guess something like
Copy code
platform:demo#super_admin@user:bob with {"attributes_match": {"expected": {"key1": "value1"},"provided": {"key1": "value1","key2": "value2"}}}
matches?
e
you don't need the caveat name in the assertion
g
ah ...
e
it's possible for multiple caveats to use the same context data
g
Btw: Is it possible to have multiple caveats on one relation?
e
yep! you just need to write it in the schema:
Copy code
relation administrator: user with caveat1 | user with caveat2
4 Views