-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
Fixes #4957 🛠️ Refactored the `purl` package. **Basic usage.** No platform information. ```go purl.NewPackageURL(nil, purl.TypeDebian, "curl", "7.50.3-1").String() ``` Will produce the purl: `pkg:deb/[email protected]` **Main usage. (with platform info)** We rely on the `inventory.Platform` that already has information like the architecture that can't change. Also we guess the linux distribution from here. ```go platform := &inventory.Platform{ Arch: "x86_64", Version: "22.04", Labels: map[string]string{ "distro-id": "jessie", }, } purl.NewPackageURL(platform, purl.TypeDebian, "curl", "7.50.3-1").String() ``` Will produce the purl: `pkg:deb/debian/[email protected]?arch=x86_64&distro=jessie` **Extended usage. (with modifiers)** We can override optional attributes, like the architecture, epoch and namespace. This is useful for non-linux systems. ```go platform := &inventory.Platform{ Name: "windows", Version: "10.0.18363", Family: []string{"windows"}, } purl.NewPackageURL(platform, purl.TypeAppx, "Microsoft.Windows.Cortana", "1.11.5.17763", purl.WithArch("x86"), purl.WithNamespace("windows"), ).String() ``` Will produce the purl: `pkg:appx/windows/[email protected]?arch=x86` --------- Signed-off-by: Salim Afiune Maya <[email protected]>
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ func TestParseAixPackages(t *testing.T) { | |
Name: "X11.apps.msmit", | ||
Version: "7.3.0.0", | ||
Description: "AIXwindows msmit Application", | ||
PUrl: "pkg:generic/aix/[email protected]?distro=aix-7.2", | ||
PUrl: "pkg:generic/aix/[email protected]?arch=powerpc&distro=aix-7.2", | ||
CPEs: []string{ | ||
"cpe:2.3:a:x11.apps.msmit:x11.apps.msmit:7.3.0.0:*:*:*:*:*:powerpc:*", | ||
"cpe:2.3:a:x11.apps.msmit:x11.apps.msmit:7.3.0:*:*:*:*:*:powerpc:*", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,19 +23,27 @@ func TestMacOsXPackageParser(t *testing.T) { | |
} | ||
assert.Nil(t, err) | ||
|
||
m, err := packages.ParseMacOSPackages(c.Stdout) | ||
pf := &inventory.Platform{ | ||
Name: "macos", | ||
Version: "15.2", | ||
Arch: "x86_64", | ||
Family: []string{"darwin", "bsd", "unix", "os"}, | ||
} | ||
m, err := packages.ParseMacOSPackages(pf, c.Stdout) | ||
assert.Nil(t, err) | ||
assert.Equal(t, 2, len(m), "detected the right amount of packages") | ||
|
||
assert.Equal(t, "Preview", m[0].Name, "pkg name detected") | ||
assert.Equal(t, "10.0", m[0].Version, "pkg version detected") | ||
assert.Equal(t, packages.MacosPkgFormat, m[0].Format, "pkg format detected") | ||
assert.Equal(t, packages.PkgFilesIncluded, m[0].FilesAvailable) | ||
assert.Equal(t, "pkg:macos/[email protected]?arch=x86_64", m[0].PUrl) | ||
assert.Equal(t, []packages.FileRecord{{Path: "/Applications/Preview.app"}}, m[0].Files) | ||
|
||
assert.Equal(t, "Contacts", m[1].Name, "pkg name detected") | ||
assert.Equal(t, "11.0", m[1].Version, "pkg version detected") | ||
assert.Equal(t, packages.MacosPkgFormat, m[1].Format, "pkg format detected") | ||
assert.Equal(t, packages.PkgFilesIncluded, m[1].FilesAvailable) | ||
assert.Equal(t, "pkg:macos/[email protected]?arch=x86_64", m[1].PUrl) | ||
assert.Equal(t, []packages.FileRecord{{Path: "/Applications/Contacts.app"}}, m[1].Files) | ||
} |