0
Fork 0
mirror of https://github.com/project-zot/zot.git synced 2024-12-30 22:34:13 -05:00

cli: group CVEs by severity

This commit is contained in:
Tanmay Naik 2020-09-04 13:56:47 -04:00
parent ebfc5958dd
commit f5867ce0b6

View file

@ -311,6 +311,8 @@ func (service searchService) getCveByImage(ctx context.Context, config searchCon
return
}
result.Data.CVEListForImage.CVEList = groupCVEsBySeverity(result.Data.CVEListForImage.CVEList)
str, err := result.string(*config.outputFormat)
if err != nil {
if isContextDone(ctx) {
@ -327,6 +329,27 @@ func (service searchService) getCveByImage(ctx context.Context, config searchCon
c <- stringResult{str, nil}
}
func groupCVEsBySeverity(cveList []cve) []cve {
high := make([]cve, 0)
med := make([]cve, 0)
low := make([]cve, 0)
for _, cve := range cveList {
switch cve.Severity {
case "LOW":
low = append(low, cve)
case "MEDIUM":
med = append(med, cve)
case "HIGH":
high = append(high, cve)
}
}
return append(append(high, med...), low...)
}
func isContextDone(ctx context.Context) bool {
select {
case <-ctx.Done():