-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathcore.rego
59 lines (40 loc) · 926 Bytes
/
core.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package lib.core
import future.keywords.if
default is_gatekeeper := false
is_gatekeeper if {
has_field(input, "review")
has_field(input.review, "object")
}
resource := input.review.object if {
is_gatekeeper
}
resource := input if {
not is_gatekeeper
}
format(msg) := {"msg": msg}
format_with_id(msg, id) := {
"msg": sprintf("%s: %s", [id, msg]),
"details": {"policyID": id},
}
apiVersion := resource.apiVersion
name := resource.metadata.name
kind := resource.kind
labels := resource.metadata.labels
annotations := resource.metadata.annotations
gv := split(apiVersion, "/")
group := gv[0] if {
contains(apiVersion, "/")
}
group := "core" if {
not contains(apiVersion, "/")
}
version := gv[count(gv) - 1]
has_field(obj, field) if {
not object.get(obj, field, "N_DEFINED") == "N_DEFINED"
}
missing_field(obj, field) if {
obj[field] == ""
}
missing_field(obj, field) if {
not has_field(obj, field)
}