github.com/kastenhq/syft@v0.0.0-20230821225854-0710af25cdbe/syft/formats/syftjson/validator.go (about) 1 package syftjson 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "io" 7 "strings" 8 9 "github.com/kastenhq/syft/syft/formats/syftjson/model" 10 ) 11 12 func validator(reader io.Reader) error { 13 type Document struct { 14 Schema model.Schema `json:"schema"` 15 } 16 17 dec := json.NewDecoder(reader) 18 19 var doc Document 20 err := dec.Decode(&doc) 21 if err != nil { 22 return fmt.Errorf("unable to decode: %w", err) 23 } 24 25 // note: we accept all schema versions 26 // TODO: add per-schema version parsing 27 if strings.Contains(doc.Schema.URL, "anchore/syft") { 28 return nil 29 } 30 return fmt.Errorf("could not extract syft schema") 31 }