mirror of
https://github.com/anchore/syft.git
synced 2026-11-03 16:06:36 +01:00
feat: Allow specific versions of formats to be specified (#1543)
This commit is contained in:
@@ -4,13 +4,31 @@ import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
|
||||
"github.com/spdx/tools-golang/convert"
|
||||
"github.com/spdx/tools-golang/spdx/v2/v2_2"
|
||||
|
||||
"github.com/anchore/syft/syft/formats/common/spdxhelpers"
|
||||
"github.com/anchore/syft/syft/sbom"
|
||||
)
|
||||
|
||||
func encoder(output io.Writer, s sbom.SBOM) error {
|
||||
func encoder2_3(output io.Writer, s sbom.SBOM) error {
|
||||
doc := spdxhelpers.ToFormatModel(s)
|
||||
return encodeJSON(output, doc)
|
||||
}
|
||||
|
||||
func encoder2_2(output io.Writer, s sbom.SBOM) error {
|
||||
doc := spdxhelpers.ToFormatModel(s)
|
||||
|
||||
var out v2_2.Document
|
||||
err := convert.Document(doc, &out)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return encodeJSON(output, out)
|
||||
}
|
||||
|
||||
func encodeJSON(output io.Writer, doc interface{}) error {
|
||||
enc := json.NewEncoder(output)
|
||||
// prevent > and < from being escaped in the payload
|
||||
enc.SetEscapeHTML(false)
|
||||
|
||||
Reference in New Issue
Block a user