Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⭐️ Add Purl to macOS and Windows systems #4996

Merged
merged 2 commits into from
Dec 17, 2024
Merged

⭐️ Add Purl to macOS and Windows systems #4996

merged 2 commits into from
Dec 17, 2024

Conversation

afiune
Copy link
Contributor

@afiune afiune commented Dec 16, 2024

Fixes #4957

Refactored the purl package.

Basic usage.

No platform information.

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.

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.

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

Copy link
Contributor

github-actions bot commented Dec 16, 2024

Test Results

3 200 tests  +29   3 198 ✅ +29   1m 43s ⏱️ -11s
  379 suites ± 0       2 💤 ± 0 
   29 files   ± 0       0 ❌ ± 0 

Results for commit 966963c. ± Comparison against base commit fee2739.

♻️ This comment has been updated with latest results.

@tas50 tas50 changed the title ⭐️ Add Purl to Macos and Windows systems ⭐️ Add Purl to macOS and Windows systems Dec 16, 2024
}
}

func ValidType(t string) bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see this being used. Did I miss something?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we use this somewhere else, could we add some tests to it?
Some types we use and some we do no longer want to use like windows_app, windows-app.

Signed-off-by: Salim Afiune Maya <[email protected]>
Copy link
Contributor

@czunker czunker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @afiune

@@ -18,6 +18,23 @@ const (
QualifierEpoch = "epoch"
)

// PackageURL is a helper struct that renters a package url based of an inventory
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renders instead of renters

//
// For more information, see:
// https://github.com/package-url/purl-spec/blob/master/PURL-TYPES.rst
func NewPackageURL(pf *inventory.Platform, t Type, name, version string, modifiers ...Modifier) *PackageURL {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That made me stumble.
First thought was, that we could derive the type from the platform. But no:

  • Windows: windows, appx, nuget, ...
  • Ubuntu: deb, snap, brew, ...
  • ...

🫤

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, we really can't 😭

@afiune afiune merged commit d12a57e into main Dec 17, 2024
17 checks passed
@afiune afiune deleted the afiune/purls branch December 17, 2024 08:10
@github-actions github-actions bot locked and limited conversation to collaborators Dec 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change windows package type
2 participants