github.com/authzed/spicedb@v1.32.1-0.20240520085336-ebda56537386/pkg/validationfile/fileformat.go (about) 1 package validationfile 2 3 import ( 4 yamlv3 "gopkg.in/yaml.v3" 5 6 "github.com/authzed/spicedb/pkg/validationfile/blocks" 7 ) 8 9 // DecodeValidationFile decodes the validation file as found in the contents bytes 10 // and returns it. 11 func DecodeValidationFile(contents []byte) (*ValidationFile, error) { 12 p := ValidationFile{} 13 err := yamlv3.Unmarshal(contents, &p) 14 if err != nil { 15 return nil, err 16 } 17 return &p, nil 18 } 19 20 // ValidationFile is a structural representation of the validation file format. 21 type ValidationFile struct { 22 // Schema is the schema. 23 Schema blocks.ParsedSchema `yaml:"schema"` 24 25 // Relationships are the relationships specified in the validation file. 26 Relationships blocks.ParsedRelationships `yaml:"relationships"` 27 28 // Assertions are the assertions defined in the validation file. May be nil 29 // if no assertions are defined. 30 Assertions blocks.Assertions `yaml:"assertions"` 31 32 // ExpectedRelations is the map of expected relations. 33 ExpectedRelations blocks.ParsedExpectedRelations `yaml:"validation"` 34 35 // NamespaceConfigs are the namespace configuration protos, in text format. 36 // Deprecated: only for internal use. Use `schema`. 37 NamespaceConfigs []string `yaml:"namespace_configs"` 38 39 // ValidationTuples are the validation tuples, in tuple string syntax. 40 // Deprecated: only for internal use. Use `relationships`. 41 ValidationTuples []string `yaml:"validation_tuples"` 42 } 43 44 // ParseAssertionsBlock parses the given contents as an assertions block. 45 func ParseAssertionsBlock(contents []byte) (*blocks.Assertions, error) { 46 return blocks.ParseAssertionsBlock(contents) 47 } 48 49 // ParseExpectedRelationsBlock parses the given contents as an expected relations block. 50 func ParseExpectedRelationsBlock(contents []byte) (*blocks.ParsedExpectedRelations, error) { 51 return blocks.ParseExpectedRelationsBlock(contents) 52 }