Skip to content

Commit

Permalink
feat: add distro mapping for azure linux 3
Browse files Browse the repository at this point in the history
Signed-off-by: Will Murphy <will.murphy@anchore.com>
  • Loading branch information
willmurphyscode committed May 7, 2024
1 parent 88b6139 commit afcd867
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions grype/db/v5/namespace/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ func (i *Index) NamespacesForDistro(d *grypeDistro.Distro) []*distro.Namespace {
if v, ok := i.byDistroKey[distroKey]; ok {
return v
}
case grypeDistro.Azure, grypeDistro.Mariner: // mariner was pre-release name for azure
distroKey = fmt.Sprintf("%s:%s", strings.ToLower(string(grypeDistro.Mariner)), d.FullVersion())
if v, ok := i.byDistroKey[distroKey]; ok {
return v
}
}
}

Expand Down
16 changes: 16 additions & 0 deletions grype/db/v5/namespace/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ func TestIndex_NamespacesForDistro(t *testing.T) {
"other-provider:distro:debian:8",
"other-provider:distro:redhat:9",
"suse:distro:sles:12.5",
"mariner:distro:mariner:2.0",
"mariner:distro:mariner:3.0",
"msrc:distro:windows:471816",
"ubuntu:distro:ubuntu:18.04",
"oracle:distro:oraclelinux:8",
Expand Down Expand Up @@ -295,6 +297,20 @@ func TestIndex_NamespacesForDistro(t *testing.T) {
distro: newDistro(t, osDistro.Mariner, "20.1", []string{}),
namespaces: nil,
},
{
name: "Mariner 2.0 matches mariner namespace",
distro: newDistro(t, osDistro.Mariner, "2.0", []string{}),
namespaces: []*distro.Namespace{
distro.NewNamespace("mariner", "mariner", "2.0"),
},
},
{
name: "azurelinux 3 is matched by mariner 3 namespace",
distro: newDistro(t, osDistro.Azure, "3.0", []string{}),
namespaces: []*distro.Namespace{
distro.NewNamespace("mariner", "mariner", "3.0"),
},
},
{
name: "Oracle Linux Major semvar matches oracle namespace with exact version",
distro: newDistro(t, osDistro.OracleLinux, "8", []string{}),
Expand Down
10 changes: 10 additions & 0 deletions grype/distro/distro_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ func Test_NewDistroFromRelease(t *testing.T) {
expectedRawVersion: "unstable",
expectedVersion: "",
},
{
name: "azure linux 3",
release: linux.Release{
ID: "azurelinux",
Version: "3.0.20240417",
VersionID: "3.0",
},
expectedType: Azure,
expectedRawVersion: "3.0",
},
}

for _, test := range tests {
Expand Down
2 changes: 2 additions & 0 deletions grype/distro/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const (
Photon Type = "photon"
Windows Type = "windows"
Mariner Type = "mariner"
Azure Type = "azurelinux"
RockyLinux Type = "rockylinux"
AlmaLinux Type = "almalinux"
Gentoo Type = "gentoo"
Expand Down Expand Up @@ -73,6 +74,7 @@ var IDMapping = map[string]Type{
"photon": Photon,
"windows": Windows,
"mariner": Mariner,
"azurelinux": Azure,
"rocky": RockyLinux,
"almalinux": AlmaLinux,
"gentoo": Gentoo,
Expand Down

0 comments on commit afcd867

Please sign in to comment.