Skip to content
This repository has been archived by the owner on Oct 1, 2023. It is now read-only.

Commit

Permalink
fix: Sorty by severity
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Pacak <pacak.daniel@gmail.com>
  • Loading branch information
danielpacak committed Jan 28, 2020
1 parent 7a83ed2 commit 6d36f5c
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions pkg/view/image_scan_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,27 @@ import (
security "github.com/danielpacak/k8s-security-crds/pkg/apis/security/v1"
"github.com/vmware-tanzu/octant/pkg/view/component"
"sort"
"strings"
)

type Severity int

const (
_ Severity = iota
SeverityUnknown
SeverityLow
SeverityMedium
SeverityHigh
SeverityCritical
)

var stringToSeverity = map[string]Severity{
"UNKNOWN": SeverityUnknown,
"LOW": SeverityLow,
"MEDIUM": SeverityMedium,
"HIGH": SeverityHigh,
"CRITICAL": SeverityCritical,
}

func NewImageScanReport(containerName string, report security.ImageScanReport) component.Component {
table := component.NewTableWithRows(
fmt.Sprintf("Image Scan Report %s", containerName), "There are no vulnerabilities!",
Expand All @@ -17,7 +35,17 @@ func NewImageScanReport(containerName string, report security.ImageScanReport) c
vulnerabilities := report.Spec.Vulnerabilities

sort.SliceStable(vulnerabilities, func(i, j int) bool {
return strings.Compare(vulnerabilities[i].Severity, vulnerabilities[j].Severity) < 0
var a, b Severity
a, ok := stringToSeverity[vulnerabilities[i].Severity]
if !ok {
a = SeverityUnknown
}
b, ok = stringToSeverity[vulnerabilities[j].Severity]
if !ok {
b = SeverityUnknown
}

return a > b
})

for _, vi := range report.Spec.Vulnerabilities {
Expand Down

0 comments on commit 6d36f5c

Please sign in to comment.