Skip to content

Commit

Permalink
Fixes format references for SBOM
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Moran authored and ryanmoran committed Mar 8, 2022
1 parent 8bb42ef commit cf9981d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions sbom/formatted_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"sync"

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

// FormattedReader outputs the SBoM in a specified format.
Expand All @@ -31,19 +31,19 @@ func (f *FormattedReader) Read(b []byte) (int, error) {
defer f.m.Unlock()

if f.reader == nil {
var option format.Option
var id sbom.FormatID
switch f.format {
case CycloneDXFormat:
option = format.CycloneDxJSONOption
id = syft.CycloneDxJSONFormatID
case SPDXFormat:
option = format.SPDXJSONOption
id = syft.SPDXJSONFormatID
case SyftFormat:
option = format.JSONOption
id = syft.JSONFormatID
default:
option = format.UnknownFormatOption
return 0, fmt.Errorf("failed to format sbom: unsupported format %q", f.format)
}

output, err := syft.Encode(f.sbom.syft, option)
output, err := syft.Encode(f.sbom.syft, syft.FormatByID(id))
if err != nil {
return 0, fmt.Errorf("failed to format sbom: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion sbom/formatted_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func testFormattedReader(t *testing.T, context spec.G, it spec.S) {
it("returns an error", func() {
formatter := sbom.NewFormattedReader(sbom.SBOM{}, sbom.Format("unknown-format"))
_, err := formatter.Read(make([]byte, 10))
Expect(err).To(MatchError("failed to format sbom: unsupported format: UnknownFormatOption"))
Expect(err).To(MatchError("failed to format sbom: unsupported format \"unknown-format\""))
})
})
})
Expand Down

0 comments on commit cf9981d

Please sign in to comment.