Skip to content

Commit

Permalink
fix(cli): sort vulnerabilities by severity
Browse files Browse the repository at this point in the history
Signed-off-by: Salim Afiune Maya <[email protected]>
  • Loading branch information
afiune committed Apr 28, 2020
1 parent 227a7b2 commit 1e0de4c
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions cli/cmd/vulnerability.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,14 +454,30 @@ func vulContainerImageLayersToTable(image *api.VulContainerImage) [][]string {
}
}

// @afiune change
sort.Slice(out, func(i, j int) bool {
return out[i][1] < out[j][1]
return severityOrder(out[i][1]) < severityOrder(out[j][1])
})

return out
}

func severityOrder(severity string) int {
switch strings.ToLower(severity) {
case "critical":
return 1
case "high":
return 2
case "medium":
return 3
case "low":
return 4
case "info":
return 5
default:
return 6
}
}

func vulContainerReportToCountsTable(report *api.VulContainerReport) [][]string {
return [][]string{
[]string{"Critical", fmt.Sprint(report.CriticalVulnerabilities),
Expand Down

0 comments on commit 1e0de4c

Please sign in to comment.