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

go2purl: Go package to Go PURL #259

Closed
Tracked by #246
pombredanne opened this issue Dec 14, 2023 · 5 comments · Fixed by package-url/packageurl-python#142 or #316
Closed
Tracked by #246

go2purl: Go package to Go PURL #259

pombredanne opened this issue Dec 14, 2023 · 5 comments · Fixed by package-url/packageurl-python#142 or #316
Assignees

Comments

@pombredanne
Copy link
Member

pombredanne commented Dec 14, 2023

Create a PURL service that takes a Go package as an input and uses Go heuristics and the Go proxy service to determine the corresponding PURL (and its companion git PURL when relevant and available)

For instance in https://github.com/istio/istio/blob/master/istioctl/pkg/authz/analyzer.go

we have these imports:

  • "github.com/envoyproxy/go-control-plane/envoy/config/listener/v3" with PURL: pkg:golang/github.com/envoyproxy/go-control-plane/envoy/config/listener/v3@1.2.3

  • "istio.io/istio/istioctl/pkg/util/configdump" with PURL: pkg:golang/istio.io/istio/istioctl/pkg/util/configdump@abcef2323232abcef2323232abcef2323232

Actually, after further review, Go uses multiple styles to reference packages/modules and their versions:

Packages

A package is a directory with a bunch of go files, and is further declared in the code of this package itself with "package foo" directives.

We cannot infer a PURL from a package only: we are missing the version and we do not know where the path or name of the modules ends.

Modules

A module is a collection of packages with a go.mod file at the root.

Modules can have a PURL and have a version (at least we know either the pinned or minimum version from the mod or sum file).

A) and E) are not in scope here, because we cannot reliably infer a module from a package short of doing extra calls. This is best done elsewhere, for instance in fetchcode.

B) and C) are in scope and the input is that of a go.mod for now. Dealing with checksums is something different that should be handled elsewhere possibly in Scancode like in https://github.com/nexB/scancode-toolkit/blob/66d71661f5ede54cb0f3b36d7663c92a67030299/src/packagedcode/go_mod.py#L206

@TG1999
Copy link
Member

TG1999 commented Jan 18, 2024

Done in package-url/packageurl-python#142

@pombredanne
Copy link
Member Author

This is available as an API function rather than a REST API endpoint as this is designed to be used as a function and not as an API call

@pombredanne pombredanne reopened this Feb 20, 2024
@pombredanne
Copy link
Member Author

Based on #246 (comment) we would have a new to_purl/go API endpoint that accepts a Go import

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Mar 3, 2024
0.14.0 (2024-02-29)
-------------------

- Add support for getting golang purl from go import.
  nexB/purldb#259

- Fix the "gem" type in the README docs.
  package-url/packageurl-python#114
@TG1999 TG1999 reopened this Mar 14, 2024
@TG1999
Copy link
Member

TG1999 commented Mar 14, 2024

This is done. We now have:

  • an endpoint /api/to_purl/go to get a package-url from a go package string that can be an import or a go package string in go.mod file like this "package version".

These 2 PRs have been merged in packageurl-python

This PR has been merged

To test this feature:

  • Install PurlDB from the main branch
  • Make a request to /api/to_purl/go?go_package={package} where package is a valid package import string or go package string in go.mod file

@TG1999 TG1999 closed this as completed Mar 14, 2024
@pombredanne
Copy link
Member Author

For info, I had also these notes:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
2 participants