Skip to content

Commit

Permalink
Add support for go packages in manifest files
Browse files Browse the repository at this point in the history
Signed-off-by: Tushar Goel <[email protected]>
  • Loading branch information
TG1999 committed Mar 7, 2024
1 parent dea7760 commit 797e20d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/packageurl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,17 @@
def get_golang_purl(go_package: str):
"""
Return a PackageURL object given an imported ``go_package``
>>> get_golang_purl(go_package="github.com/gorilla/mux v1.8.1")
PackageURL(type="golang", namespace="github.com/gorilla", name="mux", version="v1.8.1")
"""
if not go_package:
return
version = None
if " " in go_package:
go_package , _ , version = go_package.rpartition(" ")
parts = go_package.split("/")
if not parts:
return
name = parts[-1]
namespace = "/".join(parts[:-1])
return PackageURL(type="golang", namespace=namespace, name=name)
return PackageURL(type="golang", namespace=namespace, name=name, version=version)
4 changes: 4 additions & 0 deletions tests/contrib/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,7 @@ def test_get_golang_purl():
)
assert golang_purl_1.name == "v3"
assert golang_purl_1.namespace == "github.com/envoyproxy/go-control-plane/envoy/config/listener"
golang_purl_2 = get_golang_purl(go_package="github.com/grpc-ecosystem/go-grpc-middleware v1.3.0")
assert "pkg:golang/github.com/grpc-ecosystem/[email protected]" == str(
golang_purl_2
)

0 comments on commit 797e20d

Please sign in to comment.