syft/internal/formats/syftjson/validator.go
Alex Goodman c1346ad62c
migrate json presenter to json format object
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
2021-10-10 18:30:04 -07:00

32 lines
589 B
Go

package syftjson
import (
"encoding/json"
"fmt"
"io"
"strings"
"github.com/anchore/syft/internal/formats/syftjson/model"
)
func validator(reader io.Reader) error {
type Document struct {
Schema model.Schema `json:"schema"`
}
dec := json.NewDecoder(reader)
var doc Document
err := dec.Decode(&doc)
if err != nil {
return fmt.Errorf("unable to decode: %w", err)
}
// note: we accept al schema versions
// TODO: add per-schema version parsing
if strings.Contains(doc.Schema.URL, "anchore/syft") {
return nil
}
return fmt.Errorf("could not extract syft schema")
}