mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
include ID_LIKE in distro detection
Signed-off-by: Alfredo Deza <adeza@anchore.com>
This commit is contained in:
parent
b3098f3423
commit
64d5554144
@ -10,6 +10,7 @@ type Distro struct {
|
||||
Type Type
|
||||
Version *hashiVer.Version
|
||||
RawVersion string
|
||||
IDLike string
|
||||
}
|
||||
|
||||
// NewUnknownDistro creates a standardized Distro object for unidentifiable distros
|
||||
@ -19,7 +20,7 @@ func NewUnknownDistro() Distro {
|
||||
}
|
||||
}
|
||||
|
||||
func NewDistro(t Type, ver string) (Distro, error) {
|
||||
func NewDistro(t Type, ver, like string) (Distro, error) {
|
||||
if ver == "" {
|
||||
return Distro{Type: t}, nil
|
||||
}
|
||||
@ -31,6 +32,7 @@ func NewDistro(t Type, ver string) (Distro, error) {
|
||||
Type: t,
|
||||
Version: verObj,
|
||||
RawVersion: ver,
|
||||
IDLike: like,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@ -33,7 +33,7 @@ func TestDistro_FullVersion(t *testing.T) {
|
||||
for _, test := range tests {
|
||||
name := fmt.Sprintf("%s:%s", test.dist, test.version)
|
||||
t.Run(name, func(t *testing.T) {
|
||||
d, err := NewDistro(test.dist, test.version)
|
||||
d, err := NewDistro(test.dist, test.version, "")
|
||||
if err != nil {
|
||||
t.Errorf("could not create distro='%+v:%+v': %+v", test.dist, test.version, err)
|
||||
}
|
||||
@ -53,29 +53,34 @@ func TestDistro_MajorVersion(t *testing.T) {
|
||||
dist Type
|
||||
version string
|
||||
expected string
|
||||
like string
|
||||
}{
|
||||
{
|
||||
version: "8",
|
||||
expected: "8",
|
||||
like: "",
|
||||
},
|
||||
{
|
||||
version: "18.04",
|
||||
expected: "18",
|
||||
like: "debian",
|
||||
},
|
||||
{
|
||||
version: "0",
|
||||
expected: "0",
|
||||
like: "",
|
||||
},
|
||||
{
|
||||
version: "18.1.2",
|
||||
expected: "18",
|
||||
like: "debian",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
name := fmt.Sprintf("%s:%s", test.dist, test.version)
|
||||
t.Run(name, func(t *testing.T) {
|
||||
d, err := NewDistro(test.dist, test.version)
|
||||
d, err := NewDistro(test.dist, test.version, test.like)
|
||||
if err != nil {
|
||||
t.Errorf("could not create distro='%+v:%+v': %+v", test.dist, test.version, err)
|
||||
}
|
||||
|
||||
@ -81,7 +81,7 @@ identifyLoop:
|
||||
return distro
|
||||
}
|
||||
|
||||
func assemble(name, version string) *Distro {
|
||||
func assemble(name, version, like string) *Distro {
|
||||
distroType, ok := IDMapping[name]
|
||||
|
||||
// Both distro and version must be present
|
||||
@ -90,7 +90,7 @@ func assemble(name, version string) *Distro {
|
||||
}
|
||||
|
||||
if ok {
|
||||
distro, err := NewDistro(distroType, version)
|
||||
distro, err := NewDistro(distroType, version, like)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
@ -101,7 +101,7 @@ func assemble(name, version string) *Distro {
|
||||
}
|
||||
|
||||
func parseOsRelease(contents string) *Distro {
|
||||
id, vers := "", ""
|
||||
id, vers, like := "", "", ""
|
||||
for _, line := range strings.Split(contents, "\n") {
|
||||
parts := strings.Split(line, "=")
|
||||
prefix := parts[0]
|
||||
@ -112,10 +112,12 @@ func parseOsRelease(contents string) *Distro {
|
||||
id = strings.TrimSpace(value)
|
||||
case "VERSION_ID":
|
||||
vers = strings.TrimSpace(value)
|
||||
case "ID_LIKE":
|
||||
like = strings.TrimSpace(value)
|
||||
}
|
||||
}
|
||||
|
||||
return assemble(id, vers)
|
||||
return assemble(id, vers, like)
|
||||
}
|
||||
|
||||
var busyboxVersionMatcher = regexp.MustCompile(`BusyBox v[\d\.]+`)
|
||||
@ -125,7 +127,7 @@ func parseBusyBox(contents string) *Distro {
|
||||
for _, match := range matches {
|
||||
parts := strings.Split(match, " ")
|
||||
version := strings.ReplaceAll(parts[1], "v", "")
|
||||
distro := assemble("busybox", version)
|
||||
distro := assemble("busybox", version, "")
|
||||
if distro != nil {
|
||||
return distro
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user