Skip to content

Commit 9a6aaa7

Browse files
committed
fix: copilot issues
Signed-off-by: Gustavo Carvalho <gustavo.carvalho@container-solutions.com>
1 parent 4fb1f2e commit 9a6aaa7

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

policies/cloud_custodian_resources_detected.rego

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,14 @@ result := object.get(input, "result", {})
1212
check_status := object.get(execution, "status", "unknown")
1313

1414
resources := object.get(result, "resources", [])
15-
resource_count := count(resources)
15+
16+
resource_count := count(resources) if {
17+
is_array(resources)
18+
}
19+
20+
resource_count := 0 if {
21+
not is_array(resources)
22+
}
1623

1724
has_resources if {
1825
is_array(resources)

policies/cloud_custodian_resources_detected_test.rego

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,17 @@ test_violation_when_check_missing_uses_unknown_check if {
101101
"remarks": "Cloud Custodian check \"unknown-check\" matched 1 resource(s)."
102102
}] with input as fixture
103103
}
104+
105+
test_no_violation_when_resources_is_not_array if {
106+
fixture := {
107+
"check": {"name": "ec2-public-ip-check"},
108+
"execution": {"status": "success", "error": "", "errors": []},
109+
"result": {
110+
"resources": null
111+
}
112+
}
113+
114+
count(cloud_custodian_resources_detected.violation) == 0 with input as fixture
115+
cloud_custodian_resources_detected.title == "Cloud Custodian check \"ec2-public-ip-check\" status=\"success\"" with input as fixture
116+
cloud_custodian_resources_detected.description == "Cloud Custodian check \"ec2-public-ip-check\" evaluated with status \"success\" and matched 0 resource(s). Execution errors (if any) are treated as violations." with input as fixture
117+
}

0 commit comments

Comments
 (0)