Skip to content

Commit

Permalink
swap SPDX tag-value formatter to single sbom document
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
  • Loading branch information
wagoodman committed Nov 2, 2021
1 parent a5df4b9 commit 95bd1fd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
10 changes: 3 additions & 7 deletions internal/formats/spdx22tagvalue/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@ package spdx22tagvalue
import (
"io"

"github.com/anchore/syft/syft/sbom"
"github.com/spdx/tools-golang/tvsaver"

"github.com/anchore/syft/syft/distro"

"github.com/anchore/syft/syft/pkg"
"github.com/anchore/syft/syft/source"
)

func encoder(output io.Writer, catalog *pkg.Catalog, srcMetadata *source.Metadata, d *distro.Distro, scope source.Scope) error {
model := toFormatModel(catalog, srcMetadata, d, scope)
func encoder(output io.Writer, s sbom.SBOM) error {
model := toFormatModel(s)
return tvsaver.Save2_2(&model, output)
}
12 changes: 6 additions & 6 deletions internal/formats/spdx22tagvalue/to_format_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import (
"fmt"
"time"

"github.com/anchore/syft/syft/sbom"

"github.com/anchore/syft/internal"
"github.com/anchore/syft/internal/formats/common/spdxhelpers"
"github.com/anchore/syft/internal/spdxlicense"
"github.com/anchore/syft/internal/version"
"github.com/anchore/syft/syft/distro"
"github.com/anchore/syft/syft/pkg"
"github.com/anchore/syft/syft/source"
"github.com/spdx/tools-golang/spdx"
)

// toFormatModel creates and populates a new JSON document struct that follows the SPDX 2.2 spec from the given cataloging results.
// nolint:funlen
func toFormatModel(catalog *pkg.Catalog, srcMetadata *source.Metadata, _ *distro.Distro, _ source.Scope) spdx.Document2_2 {
func toFormatModel(s sbom.SBOM) spdx.Document2_2 {
return spdx.Document2_2{
CreationInfo: &spdx.CreationInfo2_2{
// 2.1: SPDX Version; should be in the format "SPDX-2.2"
Expand All @@ -33,7 +33,7 @@ func toFormatModel(catalog *pkg.Catalog, srcMetadata *source.Metadata, _ *distro

// 2.4: Document Name
// Cardinality: mandatory, one
DocumentName: srcMetadata.ImageMetadata.UserInput,
DocumentName: s.Source.ImageMetadata.UserInput,

// 2.5: Document Namespace
// Cardinality: mandatory, one
Expand All @@ -52,7 +52,7 @@ func toFormatModel(catalog *pkg.Catalog, srcMetadata *source.Metadata, _ *distro
// In many cases, the URI will point to a web accessible document, but this should not be assumed
// to be the case.

DocumentNamespace: fmt.Sprintf("https://anchore.com/syft/image/%s", srcMetadata.ImageMetadata.UserInput),
DocumentNamespace: fmt.Sprintf("https://anchore.com/syft/image/%s", s.Source.ImageMetadata.UserInput),

// 2.6: External Document References
// Cardinality: optional, one or many
Expand Down Expand Up @@ -81,7 +81,7 @@ func toFormatModel(catalog *pkg.Catalog, srcMetadata *source.Metadata, _ *distro
// Cardinality: optional, one
DocumentComment: "",
},
Packages: toFormatPackages(catalog),
Packages: toFormatPackages(s.Artifacts.PackageCatalog),
}
}

Expand Down

0 comments on commit 95bd1fd

Please sign in to comment.