0
Fork 0
mirror of https://github.com/project-zot/zot.git synced 2024-12-16 21:56:37 -05:00

Merge pull request #133 from tsnaik/cve-sort

cli: group CVEs by severity
This commit is contained in:
Ramkumar Chinchani 2020-09-08 09:29:17 -07:00 committed by GitHub
commit aa6683854f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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():