Skip to content

Commit 821591c

Browse files
authored
Merge pull request #32 from hermannloose/caveat-partial-binding
Add example for partial binding of caveat context
2 parents 9b28150 + 78ea6c7 commit 821591c

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

schemas/caveats/schema-and-data.yaml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,37 @@ schema: |-
1010
day_of_week == 'tuesday'
1111
}
1212
13+
caveat ip_allowlist(user_ip ipaddress, cidr string) {
14+
user_ip.in_cidr(cidr)
15+
}
16+
1317
definition document {
1418
/**
15-
* reader indicates that the user is a reader on the document, either directly
16-
* or only on tuesday.
19+
* reader indicates that the user is a reader on the document, either directly,
20+
* only on tuesday, or from allowed IPs.
1721
*/
18-
relation reader: user | user with only_on_tuesday
22+
relation reader: user | user with only_on_tuesday | user with ip_allowlist
1923
2024
permission view = reader
2125
}
2226
relationships: |-
2327
document:firstdoc#reader@user:fred
2428
document:firstdoc#reader@user:tom[only_on_tuesday]
29+
document:firstdoc#reader@user:alice[ip_allowlist:{"cidr":"1.2.3.0/24"}]
2530
assertions:
2631
assertTrue:
2732
- 'document:firstdoc#view@user:tom with {"day_of_week": "tuesday"}'
2833
- "document:firstdoc#view@user:fred"
34+
- 'document:firstdoc#view@user:alice with {"user_ip": "1.2.3.4"}'
2935
assertCaveated:
3036
- "document:firstdoc#view@user:tom"
37+
- "document:firstdoc#view@user:alice"
3138
assertFalse:
3239
- 'document:firstdoc#view@user:tom with {"day_of_week": "wednesday"}'
40+
- 'document:firstdoc#view@user:alice with {"user_ip": "8.8.8.8"}'
3341
validation:
3442
document:firstdoc#view:
3543
- "[user:fred] is <document:firstdoc#reader>"
3644
- "[user:tom[...]] is <document:firstdoc#reader>"
45+
- "[user:alice[...]] is <document:firstdoc#reader>"
3746
document:seconddoc#view: []

0 commit comments

Comments
 (0)