Skip to content

Commit

Permalink
feat: add supplier to SPDX documents (#79)
Browse files Browse the repository at this point in the history
When enriching with ecosyste.ms, add the supplier of a package
to an SPDX document.

Closes #76.

Co-authored-by: Gary O'Neall <[email protected]>
  • Loading branch information
mcombuechen and goneall authored Oct 24, 2024
1 parent c51c0c9 commit 327a30a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/ecosystems/enrich_spdx.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/package-url/packageurl-go"
"github.com/rs/zerolog"
"github.com/spdx/tools-golang/spdx"
"github.com/spdx/tools-golang/spdx/v2/common"
"github.com/spdx/tools-golang/spdx/v2/v2_3"

"github.com/snyk/parlay/ecosystems/packages"
Expand Down Expand Up @@ -53,6 +54,7 @@ func enrichSPDX(bom *spdx.Document, logger *zerolog.Logger) {
enrichSPDXDescription(pkg, pkgData)
enrichSPDXLicense(pkg, pkgData)
enrichSPDXHomepage(pkg, pkgData)
enrichSPDXSupplier(pkg, pkgData)
}
}

Expand All @@ -70,6 +72,20 @@ func extractPurl(pkg *v2_3.Package) (*packageurl.PackageURL, error) {
return nil, errors.New("no purl found on SPDX package")
}

func enrichSPDXSupplier(pkg *v2_3.Package, data *packages.Package) {
if data.RepoMetadata != nil {
meta := *data.RepoMetadata
if ownerRecord, ok := meta["owner_record"].(map[string]interface{}); ok {
if name, ok := ownerRecord["name"].(string); ok {
pkg.PackageSupplier = &common.Supplier{
SupplierType: "Organization",
Supplier: name,
}
}
}
}
}

func enrichSPDXLicense(pkg *v2_3.Package, data *packages.Package) {
if len(data.NormalizedLicenses) == 1 {
pkg.PackageLicenseConcluded = data.NormalizedLicenses[0]
Expand Down
7 changes: 7 additions & 0 deletions lib/ecosystems/enrich_spdx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ func TestEnrichSBOM_SPDX(t *testing.T) {
"BSD-3-Clause",
},
"homepage": "https://github.com/spdx/tools-golang",
"repo_metadata": map[string]interface{}{
"owner_record": map[string]interface{}{
"name": "Acme Corp",
},
},
})
})

Expand Down Expand Up @@ -70,6 +75,8 @@ func TestEnrichSBOM_SPDX(t *testing.T) {
assert.Equal(t, "description", pkgs[0].PackageDescription)
assert.Equal(t, "BSD-3-Clause", pkgs[0].PackageLicenseConcluded)
assert.Equal(t, "https://github.com/spdx/tools-golang", pkgs[0].PackageHomePage)
assert.Equal(t, "Organization", pkgs[0].PackageSupplier.SupplierType)
assert.Equal(t, "Acme Corp", pkgs[0].PackageSupplier.Supplier)

httpmock.GetTotalCallCount()
calls := httpmock.GetCallCountInfo()
Expand Down

0 comments on commit 327a30a

Please sign in to comment.