mirror of
https://github.com/anchore/grype
synced 2024-11-10 06:34:13 +00:00
Restore behavior of JSON distro block (#643)
This commit is contained in:
parent
55b71405ab
commit
3a22a56d11
5 changed files with 31 additions and 9 deletions
|
@ -34,7 +34,7 @@
|
|||
}
|
||||
},
|
||||
"distro": {
|
||||
"name": "",
|
||||
"name": "centos",
|
||||
"version": "8.0",
|
||||
"idLike": [
|
||||
"rhel"
|
||||
|
|
|
@ -165,7 +165,7 @@
|
|||
"target": "/some/path"
|
||||
},
|
||||
"distro": {
|
||||
"name": "",
|
||||
"name": "centos",
|
||||
"version": "8.0",
|
||||
"idLike": [
|
||||
"rhel"
|
||||
|
|
|
@ -230,7 +230,7 @@
|
|||
}
|
||||
},
|
||||
"distro": {
|
||||
"name": "",
|
||||
"name": "centos",
|
||||
"version": "8.0",
|
||||
"idLike": [
|
||||
"rhel"
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package models
|
||||
|
||||
import (
|
||||
"github.com/anchore/grype/grype/distro"
|
||||
"github.com/anchore/grype/internal/log"
|
||||
"github.com/anchore/syft/syft/linux"
|
||||
)
|
||||
|
||||
|
@ -12,14 +14,34 @@ type distribution struct {
|
|||
}
|
||||
|
||||
// newDistribution creates a struct with the Linux distribution to be represented in JSON.
|
||||
func newDistribution(d *linux.Release) distribution {
|
||||
if d == nil {
|
||||
func newDistribution(r *linux.Release) distribution {
|
||||
if r == nil {
|
||||
return distribution{}
|
||||
}
|
||||
|
||||
// attempt to use the strong distro type (like the matchers do)
|
||||
d, err := distro.NewFromRelease(*r)
|
||||
if err != nil {
|
||||
log.Warnf("unable to determine linux distribution: %+v", err)
|
||||
|
||||
// as a fallback use the raw release information
|
||||
return distribution{
|
||||
Name: r.ID,
|
||||
Version: r.VersionID,
|
||||
IDLike: cleanIDLike(r.IDLike),
|
||||
}
|
||||
}
|
||||
|
||||
return distribution{
|
||||
Name: d.Name,
|
||||
Version: d.Version,
|
||||
IDLike: d.IDLike,
|
||||
Name: d.Name(),
|
||||
Version: d.FullVersion(),
|
||||
IDLike: cleanIDLike(d.IDLike),
|
||||
}
|
||||
}
|
||||
|
||||
func cleanIDLike(idLike []string) []string {
|
||||
if idLike == nil {
|
||||
return make([]string, 0)
|
||||
}
|
||||
return idLike
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Identified distro as centos version 8.0.
|
||||
Identified distro as redhat version 8.0.
|
||||
Vulnerability: CVE-1999-0001
|
||||
Severity: Low
|
||||
Package: package-1 version 1.1.1 (deb)
|
||||
|
|
Loading…
Reference in a new issue