Skip to content

Commit

Permalink
fix: mapping of severity UNKNOWN to policy report (#1037)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikgb committed Jul 20, 2024
1 parent f31d85f commit a5a6b74
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions internal/controller/stas/policy_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,28 @@ func policyReportResultPatch(v stasv1alpha1.Vulnerability) *policyv1alpha2ac.Pol
return len(v) == 0
})

return policyv1alpha2ac.PolicyReportResult().
report := policyv1alpha2ac.PolicyReportResult().
WithCategory("vulnerability scan").
WithSource("image-scanner").
WithPolicy(v.VulnerabilityID).
WithResult(severityToPolicyResult(v.Severity)).
WithSeverity(severityToPolicyResultSeverity(v.Severity)).
WithDescription(v.Title).
WithProperties(properties)

if s, ok := severityToPolicyResultSeverity(v.Severity); ok {
report = report.
WithSeverity(s)
}

return report
}

func severityToPolicyResultSeverity(severity stasv1alpha1.Severity) policyv1alpha2.PolicyResultSeverity {
func severityToPolicyResultSeverity(severity stasv1alpha1.Severity) (policyv1alpha2.PolicyResultSeverity, bool) {
switch severity {
case stasv1alpha1.SeverityUnknown:
return ""
return "", false
default:
return policyv1alpha2.PolicyResultSeverity(strings.ToLower(severity.String()))
return policyv1alpha2.PolicyResultSeverity(strings.ToLower(severity.String())), true
}
}

Expand Down

0 comments on commit a5a6b74

Please sign in to comment.