-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added multiple validation files parsing support #455
Added multiple validation files parsing support #455
Conversation
Signed-off-by: Kartikay <kartikay_2101ce32@iitp.ac.in>
@kartikaysaxena as a temporary fix for the linting stuff, you can install a git SHA with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments - the assumption about using the first schema file for the dev context is the only part that I'd like to change. The other points are more for discussion.
@@ -105,6 +105,30 @@ func directHTTPDecoder(u *url.URL) Func { | |||
} | |||
} | |||
|
|||
// Uses the files passed in the args and looks for the specified schemaFile to parse the YAML. | |||
func unmarshalAsYAMLOrSchemaWithFile(data []byte, out interface{}, args []string) (bool, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add validation for the case where a user specifies both the schema and the schemafile?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When both schema
and schemaFIle
are provided, it directly goes to yaml.Unmarshal()
which prefers schema
over schemaFile
.
@@ -71,7 +71,7 @@ var validateCmd = &cobra.Command{ | |||
|
|||
From a devtools instance: | |||
zed validate https://localhost:8443/download`, | |||
Args: cobra.ExactArgs(1), | |||
Args: cobra.MinimumNArgs(1), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
data, err = io.ReadAll(file) | ||
if err != nil { | ||
return false, err | ||
} | ||
} | ||
} | ||
} | ||
return unmarshalAsYAMLOrSchema(data, out) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... I suppose that one implication of doing it this way is that one yaml file could reference another. Is that desirable? Genuine question; I don't know the answer. I think I'm fine with it, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can add maybe some identifiers to prevent this if not desirable.
schema := out.(*validationfile.ValidationFile) | ||
|
||
for _, arg := range args { | ||
if strings.Contains(arg, schema.SchemaFile) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this check do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checks if the file is present in the arguments provided to validate
23bd84e
to
2bb29e8
Compare
Signed-off-by: Kartikay <kartikay_2101ce32@iitp.ac.in>
2bb29e8
to
dc5852f
Compare
This is looking good to me. Can you look into the lint failures? Then we'll get the SpiceDB PR merged and we can update this PR to point at that SpiceDB commit. |
f6d132d
to
c5282b6
Compare
Signed-off-by: Kartikay <kartikay_2101ce32@iitp.ac.in>
e7e9d0e
to
2ee39b6
Compare
This looks great! Thank you! |
Related #453 #454
zed validate
now takes in multiple args to validate, also looks forschemaFile
in given .yaml validation files to parse the schema. Example usage:-Edit: Raised authzed/spicedb#2206 to introduce schemaFile which would fix the tests here too