Skip to content

Commit

Permalink
use import path for package PURLs
Browse files Browse the repository at this point in the history
this is also to better represent stdlib packages, see package-url/purl-spec#113

Signed-off-by: nscuro <[email protected]>
  • Loading branch information
nscuro committed Nov 21, 2021
1 parent 9a6d994 commit 5ef2870
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions internal/sbom/convert/pkg/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
package pkg

import (
"fmt"
"path/filepath"
"strings"

cdx "github.com/CycloneDX/cyclonedx-go"
"github.com/CycloneDX/cyclonedx-gomod/internal/gomod"
Expand Down Expand Up @@ -83,19 +83,11 @@ func ToComponent(p gomod.Package, m gomod.Module, options ...Option) (*cdx.Compo
Str("package", p.ImportPath).
Msg("converting package to component")

purl := m.PackageURL()
purl += "?type=package"
if p.ImportPath != m.Path {
pkgPath := strings.TrimPrefix(p.ImportPath, m.Path)
pkgPath = strings.TrimPrefix(pkgPath, "/")
purl = purl + "#" + pkgPath
}

component := cdx.Component{
Type: cdx.ComponentTypeLibrary,
Name: p.ImportPath,
Version: m.Version,
PackageURL: purl,
PackageURL: fmt.Sprintf("pkg:golang/%s@%s?type=package", p.ImportPath, m.Version),
}

for _, option := range options {
Expand Down

0 comments on commit 5ef2870

Please sign in to comment.