Improve sort logics
This commit is contained in:
@@ -463,7 +463,11 @@ func (p *ReportCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}
|
||||
|
||||
var res models.ScanResults
|
||||
for _, r := range results {
|
||||
//TODO remove
|
||||
res = append(res, r.FilterByCvssOver())
|
||||
|
||||
// TODO Add sort function to ScanResults
|
||||
|
||||
//remove
|
||||
// for _, vuln := range r.ScannedCves {
|
||||
// // if _, ok := vuln.CveContents.Get(models.NewCveContentType(r.Family)); !ok {
|
||||
// // pp.Printf("not in oval: %s %f\n%v\n",
|
||||
@@ -477,7 +481,6 @@ func (p *ReportCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}
|
||||
// // pp.Println(vuln)
|
||||
// // }
|
||||
// }
|
||||
res = append(res, r.FilterByCvssOver())
|
||||
}
|
||||
|
||||
for _, w := range reports {
|
||||
@@ -490,7 +493,6 @@ func (p *ReportCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}
|
||||
}
|
||||
|
||||
// fillCveDetail fetches NVD, JVN from CVE Database, and then set to fields.
|
||||
//TODO rename to FillCveDictionary
|
||||
func fillCveDetail(r *models.ScanResult) error {
|
||||
var cveIDs []string
|
||||
for _, v := range r.ScannedCves {
|
||||
@@ -515,10 +517,13 @@ func fillCveDetail(r *models.ScanResult) error {
|
||||
}
|
||||
}
|
||||
}
|
||||
//TODO sort
|
||||
// sort.Sort(r.KnownCves)
|
||||
// sort.Sort(r.UnknownCves)
|
||||
// sort.Sort(r.IgnoredCves)
|
||||
//TODO Remove
|
||||
// sort.Slice(r.ScannedCves, func(i, j int) bool {
|
||||
// if r.ScannedCves[j].CveContents.CvssV2Score() == r.ScannedCves[i].CveContents.CvssV2Score() {
|
||||
// return r.ScannedCves[j].CveContents.CvssV2Score() < r.ScannedCves[i].CveContents.CvssV2Score()
|
||||
// }
|
||||
// return r.ScannedCves[j].CveContents.CvssV2Score() < r.ScannedCves[i].CveContents.CvssV2Score()
|
||||
// })
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -44,17 +44,6 @@ var jsonDirPattern = regexp.MustCompile(
|
||||
// JSONDirs is array of json files path.
|
||||
type jsonDirs []string
|
||||
|
||||
// sort as recent directories are at the head
|
||||
func (d jsonDirs) Len() int {
|
||||
return len(d)
|
||||
}
|
||||
func (d jsonDirs) Swap(i, j int) {
|
||||
d[i], d[j] = d[j], d[i]
|
||||
}
|
||||
func (d jsonDirs) Less(i, j int) bool {
|
||||
return d[j] < d[i]
|
||||
}
|
||||
|
||||
// getValidJSONDirs return valid json directory as array
|
||||
// Returned array is sorted so that recent directories are at the head
|
||||
func lsValidJSONDirs() (dirs jsonDirs, err error) {
|
||||
@@ -69,7 +58,9 @@ func lsValidJSONDirs() (dirs jsonDirs, err error) {
|
||||
dirs = append(dirs, jsonDir)
|
||||
}
|
||||
}
|
||||
sort.Sort(dirs)
|
||||
sort.Slice(dirs, func(i, j int) bool {
|
||||
return dirs[j] < dirs[i]
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user