aboutcode-org / purldb

Tools to create and expose a database of purls (Package URLs). This project is sponsored by NLnet project https://nlnet.nl/project/vulnerabilitydatabase/ and nexB for https://www.aboutcode.org/ Chat is at https://gitter.im/aboutcode-org/discuss
https://purldb.readthedocs.io/
35 stars 21 forks source link

go2purl: Go package to Go PURL #259

Closed pombredanne closed 7 months ago

pombredanne commented 10 months ago

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:

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 commented 9 months ago

Done in https://github.com/package-url/packageurl-python/pull/142

pombredanne commented 8 months ago

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 commented 8 months ago

Based on https://github.com/nexB/purldb/issues/246#issuecomment-1953970478 we would have a new to_purl/go API endpoint that accepts a Go import

TG1999 commented 7 months ago

This is done. We now have:

These 2 PRs have been merged in packageurl-python

This PR has been merged

To test this feature:

pombredanne commented 6 months ago

For info, I had also these notes: