mirror of
https://github.com/anchore/syft.git
synced 2026-11-01 06:56:40 +01:00
experiment with encoder/decoder for data encapsulation
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
@@ -15,7 +15,7 @@ import (
|
||||
// TODO: eventually this is the source of truth for all formatters
|
||||
func All() []format.Format {
|
||||
return []format.Format{
|
||||
syftjson.Format(),
|
||||
syftjson.Format( /*...now there is a requirement for app config here...*/ ),
|
||||
table.Format(),
|
||||
cyclonedx12xml.Format(),
|
||||
spdx22json.Format(),
|
||||
|
||||
@@ -10,7 +10,10 @@ import (
|
||||
"github.com/anchore/syft/internal/formats/syftjson/model"
|
||||
)
|
||||
|
||||
func decoder(reader io.Reader) (*sbom.SBOM, error) {
|
||||
type decoder struct {
|
||||
}
|
||||
|
||||
func (d decoder) Decode(reader io.Reader) (*sbom.SBOM, error) {
|
||||
dec := json.NewDecoder(reader)
|
||||
|
||||
var doc model.Document
|
||||
|
||||
@@ -7,8 +7,12 @@ import (
|
||||
"github.com/anchore/syft/syft/sbom"
|
||||
)
|
||||
|
||||
func encoder(output io.Writer, s sbom.SBOM, appConfig interface{}) error {
|
||||
doc := ToFormatModel(s, appConfig)
|
||||
type encoder struct {
|
||||
appConfig interface{}
|
||||
}
|
||||
|
||||
func (e encoder) Encode(output io.Writer, s sbom.SBOM) error {
|
||||
doc := ToFormatModel(s, e.appConfig)
|
||||
|
||||
enc := json.NewEncoder(output)
|
||||
// prevent > and < from being escaped in the payload
|
||||
|
||||
@@ -2,11 +2,25 @@ package syftjson
|
||||
|
||||
import "github.com/anchore/syft/syft/format"
|
||||
|
||||
func Format() format.Format {
|
||||
func Format(appConfig interface{}) format.Format {
|
||||
return format.NewFormat(
|
||||
format.JSONOption,
|
||||
encoder,
|
||||
decoder,
|
||||
validator,
|
||||
Encoder(appConfig),
|
||||
Decoder(),
|
||||
Validator(),
|
||||
)
|
||||
}
|
||||
|
||||
func Encoder(appConfig interface{}) format.Encoder {
|
||||
return &encoder{
|
||||
appConfig: appConfig,
|
||||
}
|
||||
}
|
||||
|
||||
func Decoder() format.Decoder {
|
||||
return &decoder{}
|
||||
}
|
||||
|
||||
func Validator() format.Validator {
|
||||
return &validator{}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,10 @@ import (
|
||||
"github.com/anchore/syft/internal/formats/syftjson/model"
|
||||
)
|
||||
|
||||
func validator(reader io.Reader) error {
|
||||
type validator struct {
|
||||
}
|
||||
|
||||
func (v validator) Validate(reader io.Reader) error {
|
||||
type Document struct {
|
||||
Schema model.Schema `json:"schema"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user