mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
* expose underlying format options Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * remove escape html options and address PR feedback Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * incorporate PR feedback Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * fix cli test Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> --------- Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
55 lines
1.0 KiB
Go
55 lines
1.0 KiB
Go
package cyclonedxjson
|
|
|
|
import (
|
|
"github.com/CycloneDX/cyclonedx-go"
|
|
|
|
"github.com/anchore/syft/syft/format/internal/cyclonedxutil"
|
|
"github.com/anchore/syft/syft/sbom"
|
|
)
|
|
|
|
const ID = cyclonedxutil.JSONFormatID
|
|
|
|
func SupportedVersions() []string {
|
|
return cyclonedxutil.SupportedVersions(ID)
|
|
}
|
|
|
|
type EncoderConfig struct {
|
|
Version string
|
|
Pretty bool // don't include spaces and newlines; same as jq -c
|
|
}
|
|
|
|
type encoder struct {
|
|
cfg EncoderConfig
|
|
cyclonedxutil.Encoder
|
|
}
|
|
|
|
func NewFormatEncoderWithConfig(cfg EncoderConfig) (sbom.FormatEncoder, error) {
|
|
enc, err := cyclonedxutil.NewEncoder(cfg.Version, cyclonedx.BOMFileFormatJSON, cfg.Pretty)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return encoder{
|
|
cfg: cfg,
|
|
Encoder: enc,
|
|
}, nil
|
|
}
|
|
|
|
func DefaultEncoderConfig() EncoderConfig {
|
|
return EncoderConfig{
|
|
Version: cyclonedxutil.DefaultVersion,
|
|
Pretty: false,
|
|
}
|
|
}
|
|
|
|
func (e encoder) ID() sbom.FormatID {
|
|
return ID
|
|
}
|
|
|
|
func (e encoder) Aliases() []string {
|
|
return []string{}
|
|
}
|
|
|
|
func (e encoder) Version() string {
|
|
return e.cfg.Version
|
|
}
|