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:
commit
aa6683854f
1 changed files with 23 additions and 0 deletions
|
@ -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():
|
||||
|
|
Loading…
Reference in a new issue