-
Notifications
You must be signed in to change notification settings - Fork 528
/
ignore.go
51 lines (41 loc) · 1.32 KB
/
ignore.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
package models
import "github.com/anchore/grype/grype/match"
type IgnoredMatch struct {
Match
AppliedIgnoreRules []IgnoreRule `json:"appliedIgnoreRules"`
}
type IgnoreRule struct {
Vulnerability string `json:"vulnerability,omitempty"`
FixState string `json:"fix-state,omitempty"`
Package *IgnoreRulePackage `json:"package,omitempty"`
}
type IgnoreRulePackage struct {
Name string `json:"name,omitempty"`
Version string `json:"version,omitempty"`
Type string `json:"type,omitempty"`
Location string `json:"location,omitempty"`
}
func newIgnoreRule(r match.IgnoreRule) IgnoreRule {
var ignoreRulePackage *IgnoreRulePackage
// We'll only set the package part of the rule not to `nil` if there are any values to fill out.
if p := r.Package; p.Name != "" || p.Version != "" || p.Type != "" || p.Location != "" {
ignoreRulePackage = &IgnoreRulePackage{
Name: r.Package.Name,
Version: r.Package.Version,
Type: r.Package.Type,
Location: r.Package.Location,
}
}
return IgnoreRule{
Vulnerability: r.Vulnerability,
FixState: r.FixState,
Package: ignoreRulePackage,
}
}
func mapIgnoreRules(rules []match.IgnoreRule) []IgnoreRule {
var result []IgnoreRule
for _, rule := range rules {
result = append(result, newIgnoreRule(rule))
}
return result
}