diff --git a/cmd/relationtuple/create.go b/cmd/relationtuple/create.go index a8ebaef45..5aeeeda1b 100644 --- a/cmd/relationtuple/create.go +++ b/cmd/relationtuple/create.go @@ -4,6 +4,7 @@ package relationtuple import ( + "bytes" "encoding/json" "fmt" "io" @@ -75,10 +76,12 @@ func readTuplesFromArg(cmd *cobra.Command, arg string) ([]*ketoapi.RelationTuple return nil, cmdx.FailSilently(cmd) } + decoder := json.NewDecoder(bytes.NewReader(fc)) + decoder.DisallowUnknownFields() // it is ok to not validate beforehand because json.Unmarshal will report errors if fc[0] == '[' { var ts []*ketoapi.RelationTuple - if err := json.Unmarshal(fc, &ts); err != nil { + if err := decoder.Decode(&ts); err != nil { _, _ = fmt.Fprintf(cmd.ErrOrStderr(), "Could not decode: %s\n", err) return nil, cmdx.FailSilently(cmd) } @@ -86,7 +89,7 @@ func readTuplesFromArg(cmd *cobra.Command, arg string) ([]*ketoapi.RelationTuple } var r ketoapi.RelationTuple - if err := json.Unmarshal(fc, &r); err != nil { + if err := decoder.Decode(&r); err != nil { _, _ = fmt.Fprintf(cmd.ErrOrStderr(), "Could not decode: %s\n", err) return nil, cmdx.FailSilently(cmd) } diff --git a/cmd/relationtuple/parse.go b/cmd/relationtuple/parse.go index 0be42382a..4a5914e8d 100644 --- a/cmd/relationtuple/parse.go +++ b/cmd/relationtuple/parse.go @@ -21,7 +21,7 @@ func NewParseCmd() *cobra.Command { Short: "Parse human readable relation tuples", Long: "Parse human readable relation tuples as used in the documentation.\n" + "Supports various output formats. Especially useful for piping into other commands by using `--format json`.\n" + - "Ignores comments (starting with `//`) and blank lines.", + "Ignores comments (lines starting with `//`) and blank lines.", Args: cobra.MinimumNArgs(1), RunE: func(cmd *cobra.Command, args []string) error { var rts []*ketoapi.RelationTuple