Skip to content

Commit ec4bf82

Browse files
wwwiljetstack-bot
authored andcommitted
Add lint rule, update test rule, add both to CI test rule (#51)
* Add lint rule, update test rule, add both to CI test rule Signed-off-by: wwwil <[email protected]> * Update AKS Basic package format and add tests Signed-off-by: wwwil <[email protected]>
1 parent d9de116 commit ec4bf82

File tree

3 files changed

+65
-7
lines changed

3 files changed

+65
-7
lines changed

Makefile

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,15 @@ bundle-all-platforms:
7171

7272
# Packages
7373

74-
package-test:
75-
cd $(ROOT_DIR) && go run ./main.go package test ./preflight-packages/examples.jetstack.io
74+
packages-lint:
75+
cd $(ROOT_DIR) && \
76+
go run . package lint $(ROOT_DIR)/preflight-packages/jetstack.io/pods && \
77+
go run . package lint $(ROOT_DIR)/preflight-packages/examples.jetstack.io/aks_basic && \
78+
go run . package lint $(ROOT_DIR)/preflight-packages/examples.jetstack.io/gke_basic
79+
80+
packages-test:
81+
cd $(ROOT_DIR) && \
82+
go run . package test $(ROOT_DIR)/preflight-packages/examples.jetstack.io
7683

7784
# Docker image
7885

@@ -96,7 +103,7 @@ export PATH:=$(GOPATH)/bin:$(PATH)
96103
ci-deps:
97104
go install golang.org/x/lint/golint
98105

99-
ci-test: ci-deps test lint
106+
ci-test: ci-deps test lint packages-test packages-lint
100107

101108
ci-build: ci-test build build-docker-image build-all-platforms bundle-all-platforms push-docker-image-canary
102109

preflight-packages/examples.jetstack.io/aks_basic/aks.rego

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package aks_basic
33
# See https://github.com/jetstack/preflight/blob/master/docs/datagatherers/aks.md for more details
44
import input.aks as aks
55

6-
# Rule 'rbac_enabled'
7-
default preflight_rbac_enabled = false
8-
preflight_rbac_enabled {
9-
aks.Cluster.properties.enableRBAC == true
6+
# RBAC Enabled
7+
rbac_enabled[message] {
8+
not aks.Cluster.properties.enableRBAC == true
9+
message := "rbac is not enabled"
1010
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package aks_basic
2+
3+
assert_allowed(output) = output {
4+
trace(sprintf("GOT: %s", [concat(",", output)]))
5+
trace("WANT: empty set")
6+
output == set()
7+
}
8+
9+
assert_violates(output, messages) = output {
10+
trace(sprintf("GOT: %s", [concat(",", output)]))
11+
trace(sprintf("WANT: %s", [concat(",", messages)]))
12+
output == messages
13+
}
14+
15+
cluster(x) = y { y := {"aks": {"Cluster": x }} }
16+
17+
# RBAC Enabled
18+
test_rbac_enabled_enabled {
19+
output := rbac_enabled with input as cluster(
20+
{
21+
"properties": {
22+
"enableRBAC": true
23+
}
24+
}
25+
)
26+
assert_allowed(output)
27+
}
28+
test_rbac_enabled_disabled {
29+
output := rbac_enabled with input as cluster(
30+
{
31+
"properties": {
32+
"enableRBAC": false
33+
}
34+
}
35+
)
36+
assert_violates(output,
37+
{
38+
"rbac is not enabled"
39+
}
40+
)
41+
}
42+
test_rbac_enabled_missing {
43+
output := rbac_enabled with input as cluster(
44+
{}
45+
)
46+
assert_violates(output,
47+
{
48+
"rbac is not enabled"
49+
}
50+
)
51+
}

0 commit comments

Comments
 (0)