-
Notifications
You must be signed in to change notification settings - Fork 0
/
cars.rego
44 lines (36 loc) · 793 Bytes
/
cars.rego
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package cars.authz
# Employees
employees := ["alice", "eve", "ricardo", "carmen"]
# Cars and their record owners
cars := {"id1234": "alice", "id2345": "alice", "id3456": "ricardo"}
default allow := false
# Allow all to get cars
allow {
some car;
cars[car]
input.method == "GET"
input.path == ["v1", "cars", car]
}
# Allow updates from employees
allow {
some car;
cars[car]
input.method == "PUT"
input.path == ["v1", "cars", car]
input.user == employees[_]
}
# Allow new cars from employees
allow {
some car;
cars[car]
input.method == "POST"
input.path == ["v1", "cars"]
input.user == employees[_]
}
# Allow owners to delete their cars
allow {
some car;
cars[car] == input.user
input.method == "DELETE"
input.path == ["v1", "cars", car]
}