mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
35 lines
630 B
Go
35 lines
630 B
Go
package syftjson
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"io"
|
|
"strings"
|
|
|
|
"github.com/anchore/syft/internal/formats/syftjson/model"
|
|
)
|
|
|
|
type validator struct {
|
|
}
|
|
|
|
func (v validator) Validate(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 all 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")
|
|
}
|