Skip to content

Commit

Permalink
✨ Add platform PURL type (#5088)
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Zunker <christian@mondoo.com>
  • Loading branch information
czunker authored Jan 14, 2025
1 parent f8106af commit 3300ea7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion providers/os/resources/purl/platform_purl.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func NewPlatformPurl(platform *inventory.Platform) (string, error) {
qualifiers[QualifierDistro] = strings.Join(distroQualifiers, "-")

return packageurl.NewPackageURL(
"platform",
string(Type_X_Platform),
platform.Name,
"",
platform.Version,
Expand Down
20 changes: 11 additions & 9 deletions providers/os/resources/purl/purl_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ var (
TypeAppx Type = "appx"
// TypeMacos is a pkg:macos purl.
TypeMacos Type = "macos"

// Type_X_Platform is a pkg:platform purl.
Type_X_Platform Type = "platform"
// Types we use coming from:
// https://github.com/package-url/packageurl-go/blob/master/packageurl.go#L54
TypeGeneric = Type(packageurl.TypeGeneric)
Expand All @@ -27,14 +28,15 @@ var (
TypeRPM = Type(packageurl.TypeRPM)

KnownTypes = map[Type]struct{}{
TypeAppx: {},
TypeWindows: {},
TypeMacos: {},
TypeGeneric: {},
TypeApk: {},
TypeDebian: {},
TypeAlpm: {},
TypeRPM: {},
TypeAppx: {},
TypeWindows: {},
TypeMacos: {},
Type_X_Platform: {},
TypeGeneric: {},
TypeApk: {},
TypeDebian: {},
TypeAlpm: {},
TypeRPM: {},
}
)

Expand Down
2 changes: 2 additions & 0 deletions providers/os/resources/purl/purl_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func TestValidType(t *testing.T) {
validTypes := []purl.Type{
purl.TypeWindows, purl.TypeAppx, purl.TypeMacos, purl.TypeGeneric,
purl.TypeApk, purl.TypeDebian, purl.TypeAlpm, purl.TypeRPM,
purl.Type_X_Platform,
}

for _, validType := range validTypes {
Expand Down Expand Up @@ -48,6 +49,7 @@ func TestValidTypeString(t *testing.T) {
string(purl.TypeWindows), string(purl.TypeAppx), string(purl.TypeMacos),
packageurl.TypeGeneric, packageurl.TypeApk, packageurl.TypeDebian,
packageurl.TypeAlpm, packageurl.TypeRPM, "windows", "appx", "macos",
"platform", string(purl.Type_X_Platform),
}

for _, validType := range validTypes {
Expand Down

0 comments on commit 3300ea7

Please sign in to comment.