-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
Copy pathvulnerability.go
61 lines (51 loc) · 2.29 KB
/
vulnerability.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package types
import (
"github.com/aquasecurity/trivy-db/pkg/types"
ftypes "github.com/aquasecurity/trivy/pkg/fanal/types"
)
// DetectedVulnerability holds the information of detected vulnerabilities
type DetectedVulnerability struct {
VulnerabilityID string `json:",omitempty"`
VendorIDs []string `json:",omitempty"`
PkgID string `json:",omitempty"` // It is used to construct dependency graph.
PkgName string `json:",omitempty"`
PkgPath string `json:",omitempty"` // This field is populated in the case of language-specific packages such as egg/wheel and gemspec
PkgIdentifier ftypes.PkgIdentifier `json:",omitempty"`
InstalledVersion string `json:",omitempty"`
FixedVersion string `json:",omitempty"`
Status types.Status `json:",omitempty"`
Layer ftypes.Layer `json:",omitempty"`
SeveritySource types.SourceID `json:",omitempty"`
PrimaryURL string `json:",omitempty"`
// DataSource holds where the advisory comes from
DataSource *types.DataSource `json:",omitempty"`
// Custom is for extensibility and not supposed to be used in OSS
Custom interface{} `json:",omitempty"`
// Embed vulnerability details
types.Vulnerability
}
func (DetectedVulnerability) findingType() FindingType { return FindingTypeVulnerability }
// BySeverity implements sort.Interface based on the Severity field.
type BySeverity []DetectedVulnerability
// Len returns the length of DetectedVulnerabilities
func (v BySeverity) Len() int { return len(v) }
// Less compares 2 DetectedVulnerabilities based on package name, severity, vulnerabilityID and package path
func (v BySeverity) Less(i, j int) bool {
if v[i].PkgName != v[j].PkgName {
return v[i].PkgName < v[j].PkgName
} else if v[i].InstalledVersion != v[j].InstalledVersion {
return v[i].InstalledVersion < v[j].InstalledVersion
}
ret := types.CompareSeverityString(
v[j].Severity, v[i].Severity,
)
if ret != 0 {
return ret > 0
}
if v[i].VulnerabilityID != v[j].VulnerabilityID {
return v[i].VulnerabilityID < v[j].VulnerabilityID
}
return v[i].PkgPath < v[j].PkgPath
}
// Swap swaps 2 vulnerability
func (v BySeverity) Swap(i, j int) { v[i], v[j] = v[j], v[i] }