mirror of
https://github.com/anchore/syft.git
synced 2025-11-18 00:43:20 +01:00
* add template output Signed-off-by: Jonas Xavier <jonasx@anchore.com> * remove dead code Signed-off-by: Jonas Xavier <jonasx@anchore.com> * fix template cli flag Signed-off-by: Jonas Xavier <jonasx@anchore.com> * implement template's own format type Signed-off-by: Jonas Xavier <jonasx@anchore.com> * simpler code Signed-off-by: Jonas Xavier <jonasx@anchore.com> * fix readme link to Go template Signed-off-by: Jonas Xavier <jonasx@anchore.com> * feedback changes Signed-off-by: Jonas Xavier <jonasx@anchore.com> * simpler func signature patter Signed-off-by: Jonas Xavier <jonasx@anchore.com> * nit Signed-off-by: Jonas Xavier <jonasx@anchore.com> * fix linter error Signed-off-by: Jonas Xavier <jonasx@anchore.com>
48 lines
985 B
Go
48 lines
985 B
Go
package template
|
|
|
|
import (
|
|
"io"
|
|
|
|
"github.com/anchore/syft/internal/formats/syftjson"
|
|
"github.com/anchore/syft/syft/sbom"
|
|
)
|
|
|
|
const ID sbom.FormatID = "template"
|
|
|
|
func Format() sbom.Format {
|
|
return OutputFormat{}
|
|
}
|
|
|
|
// implementation of sbom.Format interface
|
|
// to make use of format options
|
|
type OutputFormat struct {
|
|
templateFilePath string
|
|
}
|
|
|
|
func (f OutputFormat) ID() sbom.FormatID {
|
|
return ID
|
|
}
|
|
|
|
func (f OutputFormat) Decode(reader io.Reader) (*sbom.SBOM, error) {
|
|
return nil, sbom.ErrDecodingNotSupported
|
|
}
|
|
|
|
func (f OutputFormat) Encode(output io.Writer, s sbom.SBOM) error {
|
|
tmpl, err := makeTemplateExecutor(f.templateFilePath)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
doc := syftjson.ToFormatModel(s)
|
|
return tmpl.Execute(output, doc)
|
|
}
|
|
|
|
func (f OutputFormat) Validate(reader io.Reader) error {
|
|
return sbom.ErrValidationNotSupported
|
|
}
|
|
|
|
// SetTemplatePath sets path for template file
|
|
func (f *OutputFormat) SetTemplatePath(filePath string) {
|
|
f.templateFilePath = filePath
|
|
}
|