Skip to content

Commit

Permalink
Don't use a special case for message formatting based on policyID (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
James Alseth authored Dec 3, 2020
1 parent 389db7f commit 722870f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
13 changes: 8 additions & 5 deletions .github/test/policy/always_warn.rego
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package always_warn

warn[msg] {
msg := {
"msg": "a warning! you should probably fix this",
"details": {"policyID": "P0000"}
}

msg := format_with_id("a warning! you should probably fix this", "P0000")
true
}

format_with_id(msg, id) = msg_fmt {
msg_fmt := {
"msg": sprintf("%s: %s", [id, msg]),
"details": {"policyID": id}
}
}
12 changes: 2 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,30 +114,22 @@ func run() error {
successes += len(result.Successes)

for _, fail := range result.Failures {
// attempt to parse the policy ID section, skip if there are errors
fails = append(fails, fmt.Sprintf("%s - %s", result.Filename, fail.Message))
policyID, err := getPolicyIDFromMetadata(fail.Metadata, policyIDKey)
if err != nil {
fails = append(fails, fmt.Sprintf("%s - %s", result.Filename, fail.Message))
continue
}

fails = append(fails, fmt.Sprintf("%s - %s: %s", result.Filename, policyID, fail.Message))

if !contains(policiesWithFails, policyID) {
policiesWithFails = append(policiesWithFails, policyID)
}
}

for _, warn := range result.Warnings {
// attempt to parse the policy ID section, skip if there are errors
warns = append(warns, fmt.Sprintf("%s - %s", result.Filename, warn.Message))
policyID, err := getPolicyIDFromMetadata(warn.Metadata, policyIDKey)
if err != nil {
warns = append(warns, fmt.Sprintf("%s - %s", result.Filename, warn.Message))
continue
}

warns = append(warns, fmt.Sprintf("%s - %s: %s", result.Filename, policyID, warn.Message))

if !contains(policiesWithWarns, policyID) {
policiesWithWarns = append(policiesWithWarns, policyID)
}
Expand Down

0 comments on commit 722870f

Please sign in to comment.