Skip to content

Commit 1338850

Browse files
authored
Add fixed-in-version to the presenters (#147)
* add fix-in-version to the json and table presenters Signed-off-by: Alex Goodman <[email protected]> * incorporate grype-db fixed-in updates Signed-off-by: Alex Goodman <[email protected]>
1 parent bd50ffc commit 1338850

File tree

9 files changed

+45
-35
lines changed

9 files changed

+45
-35
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/adrg/xdg v0.2.1
77
github.com/anchore/go-testutils v0.0.0-20200624184116-66aa578126db
88
github.com/anchore/go-version v1.2.2-0.20200810141238-330bef18dbca
9-
github.com/anchore/grype-db v0.0.0-20200807151757-5aee0401bf56
9+
github.com/anchore/grype-db v0.0.0-20200909132108-9474dd8f080f
1010
github.com/anchore/stereoscope v0.0.0-20200813152757-548b22c8a0b3
1111
github.com/anchore/syft v0.1.0-beta.4.0.20200827121056-d85d0ac418a7
1212
github.com/dustin/go-humanize v1.0.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ github.com/anchore/go-version v1.2.2-0.20200701162849-18adb9c92b9b h1:e1bmaoJfZV
121121
github.com/anchore/go-version v1.2.2-0.20200701162849-18adb9c92b9b/go.mod h1:Bkc+JYWjMCF8OyZ340IMSIi2Ebf3uwByOk6ho4wne1E=
122122
github.com/anchore/go-version v1.2.2-0.20200810141238-330bef18dbca h1:rLyc7Rih769rYABQe4nBPt3jHJd/snBuVvKKGoy5HEc=
123123
github.com/anchore/go-version v1.2.2-0.20200810141238-330bef18dbca/go.mod h1:Bkc+JYWjMCF8OyZ340IMSIi2Ebf3uwByOk6ho4wne1E=
124-
github.com/anchore/grype-db v0.0.0-20200807151757-5aee0401bf56 h1:Hf1i3Imipp+2dmf70U+l7+aYIkzfd3myoUG0t+dBw5w=
125-
github.com/anchore/grype-db v0.0.0-20200807151757-5aee0401bf56/go.mod h1:LINmipRzG88vnJEWvgMMDVCFH1qZsj7+bjmpERlSyaA=
124+
github.com/anchore/grype-db v0.0.0-20200909132108-9474dd8f080f h1:/6h4PkxPn0VQ3EjvTKfiPHdpI1TYqRMMywatd81HX3Y=
125+
github.com/anchore/grype-db v0.0.0-20200909132108-9474dd8f080f/go.mod h1:LINmipRzG88vnJEWvgMMDVCFH1qZsj7+bjmpERlSyaA=
126126
github.com/anchore/stereoscope v0.0.0-20200520221116-025e07f1c93e h1:QBwtrM0MXi0z+GcHk3RoSyzaQ+CLgas0bC/uOd1P+PQ=
127127
github.com/anchore/stereoscope v0.0.0-20200520221116-025e07f1c93e/go.mod h1:bkyLl5VITnrmgErv4S1vDfVz/TGAZ5il6161IQo7w2g=
128128
github.com/anchore/stereoscope v0.0.0-20200813152757-548b22c8a0b3 h1:pl+txuYlhK8Mmio4d+4zQI/1xg8X6BtNErTASrx23Wk=

grype/presenter/json/presenter_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,9 @@ func TestJsonPresenter(t *testing.T) {
9292
var match1 = match.Match{
9393
Type: match.ExactDirectMatch,
9494
Vulnerability: vulnerability.Vulnerability{
95-
ID: "CVE-1999-0001",
96-
RecordSource: "source-1",
95+
ID: "CVE-1999-0001",
96+
RecordSource: "source-1",
97+
FixedInVersion: "the-next-version",
9798
},
9899
Package: &pkg1,
99100
Matcher: match.DpkgMatcher,
@@ -127,8 +128,9 @@ func TestJsonPresenter(t *testing.T) {
127128
var match3 = match.Match{
128129
Type: match.ExactIndirectMatch,
129130
Vulnerability: vulnerability.Vulnerability{
130-
ID: "CVE-1999-0003",
131-
RecordSource: "source-1",
131+
ID: "CVE-1999-0003",
132+
RecordSource: "source-1",
133+
FixedInVersion: "the-other-next-version",
132134
},
133135
Package: &pkg1,
134136
Matcher: match.DpkgMatcher,

grype/presenter/json/test-fixtures/snapshot/TestJsonPresenter.golden

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"cvss-v3": {
77
"base-score": 4,
88
"vector": "another vector"
9-
}
9+
},
10+
"fixed-in-version": "the-next-version"
1011
},
1112
"match-details": {
1213
"matcher": "dpkg-matcher",
@@ -73,7 +74,8 @@
7374
{
7475
"vulnerability": {
7576
"id": "CVE-1999-0003",
76-
"description": "1999-03 description"
77+
"description": "1999-03 description",
78+
"fixed-in-version": "the-other-next-version"
7779
},
7880
"match-details": {
7981
"matcher": "dpkg-matcher",

grype/presenter/json/vulnerability.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ type Cvss struct {
1313
}
1414

1515
type Vulnerability struct {
16-
ID string `json:"id"`
17-
Severity string `json:"severity,omitempty"`
18-
Links []string `json:"links,omitempty"`
19-
Description string `json:"description,omitempty"`
20-
CvssV2 *Cvss `json:"cvss-v2,omitempty"`
21-
CvssV3 *Cvss `json:"cvss-v3,omitempty"`
16+
ID string `json:"id"`
17+
Severity string `json:"severity,omitempty"`
18+
Links []string `json:"links,omitempty"`
19+
Description string `json:"description,omitempty"`
20+
CvssV2 *Cvss `json:"cvss-v2,omitempty"`
21+
CvssV3 *Cvss `json:"cvss-v3,omitempty"`
22+
FixedInVersion string `json:"fixed-in-version,omitempty"`
2223
}
2324

2425
func NewVulnerability(m match.Match, metadata *vulnerability.Metadata) Vulnerability {
@@ -63,11 +64,12 @@ func NewVulnerability(m match.Match, metadata *vulnerability.Metadata) Vulnerabi
6364
}
6465

6566
return Vulnerability{
66-
ID: m.Vulnerability.ID,
67-
Severity: metadata.Severity,
68-
Links: metadata.Links,
69-
Description: metadata.Description,
70-
CvssV2: cvssV2,
71-
CvssV3: cvssV3,
67+
ID: m.Vulnerability.ID,
68+
Severity: metadata.Severity,
69+
Links: metadata.Links,
70+
Description: metadata.Description,
71+
CvssV2: cvssV2,
72+
CvssV3: cvssV3,
73+
FixedInVersion: m.Vulnerability.FixedInVersion,
7274
}
7375
}

grype/presenter/table/presenter.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func NewPresenter(results result.Result, catalog *pkg.Catalog, metadataProvider
3131
func (pres *Presenter) Present(output io.Writer) error {
3232
rows := make([][]string, 0)
3333

34-
columns := []string{"Name", "Installed", "Vulnerability", "Severity"}
34+
columns := []string{"Name", "Installed", "Fixed-In", "Vulnerability", "Severity"}
3535
for m := range pres.results.Enumerate() {
3636
var severity string
3737

@@ -47,6 +47,7 @@ func (pres *Presenter) Present(output io.Writer) error {
4747
row := []string{
4848
m.Package.Name,
4949
m.Package.Version,
50+
m.Vulnerability.FixedInVersion,
5051
m.Vulnerability.ID,
5152
severity,
5253
}

grype/presenter/table/presenter_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ func TestTablePresenter(t *testing.T) {
8888
var match2 = match.Match{
8989
Type: match.ExactIndirectMatch,
9090
Vulnerability: vulnerability.Vulnerability{
91-
ID: "CVE-1999-0002",
92-
RecordSource: "source-2",
91+
ID: "CVE-1999-0002",
92+
RecordSource: "source-2",
93+
FixedInVersion: "the-next-version",
9394
},
9495
Package: &pkg2,
9596
Matcher: match.DpkgMatcher,
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
NAME INSTALLED VULNERABILITY SEVERITY
2-
package-1 1.0.1 CVE-1999-0001 Low
3-
package-2 2.0.1 CVE-1999-0002 Critical
1+
NAME INSTALLED FIXED-IN VULNERABILITY SEVERITY
2+
package-1 1.0.1 CVE-1999-0001 Low
3+
package-2 2.0.1 the-next-version CVE-1999-0002 Critical

grype/vulnerability/vulnerability.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ import (
99
)
1010

1111
type Vulnerability struct {
12-
Constraint version.Constraint
13-
CPEs []cpe.CPE
14-
ID string
15-
RecordSource string
12+
Constraint version.Constraint
13+
CPEs []cpe.CPE
14+
ID string
15+
RecordSource string
16+
FixedInVersion string
1617
}
1718

1819
func NewVulnerability(vuln v1.Vulnerability) (*Vulnerability, error) {
@@ -24,10 +25,11 @@ func NewVulnerability(vuln v1.Vulnerability) (*Vulnerability, error) {
2425
}
2526

2627
return &Vulnerability{
27-
Constraint: constraint,
28-
ID: vuln.ID,
29-
CPEs: make([]cpe.CPE, 0),
30-
RecordSource: vuln.RecordSource,
28+
Constraint: constraint,
29+
ID: vuln.ID,
30+
CPEs: make([]cpe.CPE, 0),
31+
RecordSource: vuln.RecordSource,
32+
FixedInVersion: vuln.FixedInVersion,
3133
}, nil
3234
}
3335

0 commit comments

Comments
 (0)