forked from plexsystems/konstraint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.rego
59 lines (41 loc) · 890 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
default is_gatekeeper = false
is_gatekeeper {
has_field(input, "review")
has_field(input.review, "object")
}
resource = input.review.object {
is_gatekeeper
}
resource = input {
not is_gatekeeper
}
format(msg) = {"msg": msg}
format_with_id(msg, id) = msg_fmt {
msg_fmt := {
"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] {
contains(apiVersion, "/")
}
group = "core" {
not contains(apiVersion, "/")
}
version := gv[count(gv) - 1]
has_field(obj, field) {
not object.get(obj, field, "N_DEFINED") == "N_DEFINED"
}
missing_field(obj, field) {
obj[field] == ""
}
missing_field(obj, field) {
not has_field(obj, field)
}