Skip to content

Commit 7171fdd

Browse files
authored
Merge pull request #44 from charlieegan3/surface-violations-in-report-json
Surface violations in report JSON
2 parents 6b0d105 + fa308eb commit 7171fdd

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

api/report.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ type ReportRule struct {
6262
Success bool `json:"success"`
6363
// Value contains the raw result of the check.
6464
Value interface{} `json:"value,omitempty"`
65+
// Violations contains the list of messages from the execution of the check
66+
Violations interface{} `json:"violations,omitempty"`
6567
// Missing indicates whether the Rego rule was missing or not.
6668
Missing bool `json:"missing"`
6769
}

pkg/exporter/json.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ func (e *JSONExporter) Export(ctx context.Context, policyManifest *packaging.Pol
5151
results := rc.ByID()
5252
result := results[ruleToResult(rule.ID)]
5353
var value interface{}
54+
violations := []string{}
5455
success := false
5556
missing := false
5657

@@ -59,6 +60,7 @@ func (e *JSONExporter) Export(ctx context.Context, policyManifest *packaging.Pol
5960
missing = true
6061
case result.IsFailureState():
6162
success = false
63+
violations = result.Violations
6264
case result.IsSuccessState():
6365
success = true
6466
default:
@@ -72,6 +74,7 @@ func (e *JSONExporter) Export(ctx context.Context, policyManifest *packaging.Pol
7274
Manual: rule.Manual,
7375
Remediation: rule.Remediation,
7476
Links: links,
77+
Violations: violations,
7578
Success: success,
7679
Value: value,
7780
Missing: missing,

pkg/exporter/json_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ func TestJSONExport(t *testing.T) {
8585
{
8686
"missing": false,
8787
"success": true,
88+
"violations": [],
8889
"links": [
8990
"http://jetstack.io/docs",
9091
"http://jetstack.io/docs2"
@@ -97,6 +98,9 @@ func TestJSONExport(t *testing.T) {
9798
{
9899
"missing": false,
99100
"success": false,
101+
"violations": [
102+
"violation"
103+
],
100104
"links": [
101105
"http://jetstack.io/docs",
102106
"http://jetstack.io/docs2"
@@ -116,6 +120,7 @@ func TestJSONExport(t *testing.T) {
116120
{
117121
"missing": true,
118122
"success": false,
123+
"violations": [],
119124
"links": [
120125
"http://jetstack.io/docs",
121126
"http://jetstack.io/docs2"

0 commit comments

Comments
 (0)