Skip to content

Commit

Permalink
throw err if schema and schemaFile not specified
Browse files Browse the repository at this point in the history
Signed-off-by: Kartikay <[email protected]>
  • Loading branch information
kartikaysaxena authored and tstirrat15 committed Jan 14, 2025
1 parent 5b73173 commit c396d74
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions pkg/validationfile/fileformat.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package validationfile

import (
"errors"
"fmt"

yamlv3 "gopkg.in/yaml.v3"

"github.com/authzed/spicedb/pkg/spiceerrors"
"github.com/authzed/spicedb/pkg/validationfile/blocks"
)

Expand Down Expand Up @@ -43,6 +47,32 @@ type ValidationFile struct {
SchemaFile string `yaml:"schemaFile"`
}

func (vf *ValidationFile) UnmarshalYAML(node *yamlv3.Node) error {
type alias ValidationFile // To avoid recursion during decoding
temp := &alias{}
if err := node.Decode(temp); err != nil {
return spiceerrors.NewWithSourceError(
fmt.Errorf("error decoding validation file: %w", err),
"validation file",
uint64(node.Line),

Check failure on line 57 in pkg/validationfile/fileformat.go

View workflow job for this annotation

GitHub Actions / Lint Go

G115: integer overflow conversion int -> uint64 (gosec)
uint64(node.Column),

Check failure on line 58 in pkg/validationfile/fileformat.go

View workflow job for this annotation

GitHub Actions / Lint Go

G115: integer overflow conversion int -> uint64 (gosec)
)
}

*vf = ValidationFile(*temp)

// Enforce either one of schema or schemaFile is set.
if vf.Schema == (blocks.ParsedSchema{}) && temp.SchemaFile == "" {
return spiceerrors.NewWithSourceError(
errors.New("validation file must specify either 'schema' or 'schemaFile'"),
"validation file",
uint64(node.Line),

Check failure on line 69 in pkg/validationfile/fileformat.go

View workflow job for this annotation

GitHub Actions / Lint Go

G115: integer overflow conversion int -> uint64 (gosec)
uint64(node.Column),
)
}
return nil
}

// ParseAssertionsBlock parses the given contents as an assertions block.
func ParseAssertionsBlock(contents []byte) (*blocks.Assertions, error) {
return blocks.ParseAssertionsBlock(contents)
Expand Down

0 comments on commit c396d74

Please sign in to comment.