From ef1934a5c1f521b13326ff85b76ed4ddab8f034b Mon Sep 17 00:00:00 2001 From: Weston Steimel Date: Tue, 15 Nov 2022 15:25:46 +0000 Subject: [PATCH] feat: add strong distro type for wolfi (#996) --- grype/db/v3/namespace.go | 2 ++ grype/db/v3/namespace_test.go | 7 ++++++- grype/db/v4/namespace/distro/namespace_test.go | 4 ++++ grype/db/v5/namespace/distro/namespace_test.go | 4 ++++ grype/distro/distro_test.go | 4 ++++ grype/distro/test-fixtures/os/wolfi/etc/os-release | 5 +++++ grype/distro/type.go | 3 +++ 7 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 grype/distro/test-fixtures/os/wolfi/etc/os-release diff --git a/grype/db/v3/namespace.go b/grype/db/v3/namespace.go index 6146027c..9ed976cb 100644 --- a/grype/db/v3/namespace.go +++ b/grype/db/v3/namespace.go @@ -71,6 +71,8 @@ func NamespaceForDistro(d *distro.Distro) string { return fmt.Sprintf("sles:%d.%d", versionSegments[0], versionSegments[1]) case distro.Windows: return fmt.Sprintf("%s:%d", MSRCNamespacePrefix, versionSegments[0]) + case distro.Wolfi: + return "wolfi:rolling" } } return fmt.Sprintf("%s:%s", strings.ToLower(d.Type.String()), d.FullVersion()) diff --git a/grype/db/v3/namespace_test.go b/grype/db/v3/namespace_test.go index 896950ea..6e64337c 100644 --- a/grype/db/v3/namespace_test.go +++ b/grype/db/v3/namespace_test.go @@ -178,9 +178,14 @@ func Test_NamespaceForDistro(t *testing.T) { }, { dist: distro.Gentoo, - version: "", // Gentoo doesn't expose a version + version: "", // Gentoo is a rolling release expected: "gentoo:", }, + { + dist: distro.Wolfi, + version: "2022yzblah", // Wolfi is a rolling release + expected: "wolfi:rolling", + }, } observedDistros := strset.New() diff --git a/grype/db/v4/namespace/distro/namespace_test.go b/grype/db/v4/namespace/distro/namespace_test.go index 01318944..f916d66b 100644 --- a/grype/db/v4/namespace/distro/namespace_test.go +++ b/grype/db/v4/namespace/distro/namespace_test.go @@ -37,6 +37,10 @@ func TestFromString(t *testing.T) { namespaceString: "amazon:distro:amazonlinux:2", result: NewNamespace("amazon", grypeDistro.AmazonLinux, "2"), }, + { + namespaceString: "wolfi:distro:wolfi:rolling", + result: NewNamespace("wolfi", grypeDistro.Wolfi, "rolling"), + }, } for _, test := range successTests { diff --git a/grype/db/v5/namespace/distro/namespace_test.go b/grype/db/v5/namespace/distro/namespace_test.go index 01318944..f916d66b 100644 --- a/grype/db/v5/namespace/distro/namespace_test.go +++ b/grype/db/v5/namespace/distro/namespace_test.go @@ -37,6 +37,10 @@ func TestFromString(t *testing.T) { namespaceString: "amazon:distro:amazonlinux:2", result: NewNamespace("amazon", grypeDistro.AmazonLinux, "2"), }, + { + namespaceString: "wolfi:distro:wolfi:rolling", + result: NewNamespace("wolfi", grypeDistro.Wolfi, "rolling"), + }, } for _, test := range successTests { diff --git a/grype/distro/distro_test.go b/grype/distro/distro_test.go index d48afad6..2be3ab35 100644 --- a/grype/distro/distro_test.go +++ b/grype/distro/distro_test.go @@ -204,6 +204,10 @@ func Test_NewDistroFromRelease_Coverage(t *testing.T) { fixture: "test-fixtures/os/gentoo", Type: Gentoo, }, + { + fixture: "test-fixtures/os/wolfi", + Type: Wolfi, + }, } observedDistros := internal.NewStringSet() diff --git a/grype/distro/test-fixtures/os/wolfi/etc/os-release b/grype/distro/test-fixtures/os/wolfi/etc/os-release new file mode 100644 index 00000000..34ecce46 --- /dev/null +++ b/grype/distro/test-fixtures/os/wolfi/etc/os-release @@ -0,0 +1,5 @@ +ID=wolfi +NAME="Wolfi" +PRETTY_NAME="Wolfi" +VERSION_ID="20220914" +HOME_URL="https://wolfi.dev" diff --git a/grype/distro/type.go b/grype/distro/type.go index cee2d2c0..f2519460 100644 --- a/grype/distro/type.go +++ b/grype/distro/type.go @@ -28,6 +28,7 @@ const ( RockyLinux Type = "rockylinux" AlmaLinux Type = "almalinux" Gentoo Type = "gentoo" + Wolfi Type = "wolfi" ) // All contains all Linux distribution options @@ -50,6 +51,7 @@ var All = []Type{ RockyLinux, AlmaLinux, Gentoo, + Wolfi, } // IDMapping connects a distro ID like "ubuntu" to a Distro type @@ -72,6 +74,7 @@ var IDMapping = map[string]Type{ "rocky": RockyLinux, "almalinux": AlmaLinux, "gentoo": Gentoo, + "wolfi": Wolfi, } func TypeFromRelease(release linux.Release) Type {