syft/internal/presenter/poweruser/json_presenter.go
Alex Goodman a3a13b4fe3
remove power-user document shape
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
2021-11-22 14:36:16 -05:00

35 lines
841 B
Go

package poweruser
import (
"encoding/json"
"io"
"github.com/anchore/syft/internal/formats/syftjson"
"github.com/anchore/syft/syft/sbom"
)
// JSONPresenter is a JSON presentation object for the syft results
type JSONPresenter struct {
sbom sbom.SBOM
config interface{}
}
// NewJSONPresenter creates a new JSON presenter object for the given cataloging results.
func NewJSONPresenter(s sbom.SBOM, appConfig interface{}) *JSONPresenter {
return &JSONPresenter{
sbom: s,
config: appConfig,
}
}
// Present the PackageCatalog results to the given writer.
func (p *JSONPresenter) Present(output io.Writer) error {
doc := syftjson.ToFormatModel(p.sbom, p.config)
enc := json.NewEncoder(output)
// prevent > and < from being escaped in the payload
enc.SetEscapeHTML(false)
enc.SetIndent("", " ")
return enc.Encode(&doc)
}