-
Notifications
You must be signed in to change notification settings - Fork 53
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 JSON input validation for CLI commands #1771
Conversation
libs/flags/json_flag.go
Outdated
@@ -33,7 +35,27 @@ func (j *JsonFlag) Unmarshal(v any) error { | |||
if j.raw == nil { | |||
return nil | |||
} | |||
return json.Unmarshal(j.raw, v) | |||
|
|||
dv, err := jsonloader.LoadJSON(j.raw) |
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.
Could we do the same for the YAML flag?
I believe that's the only reason we still depend on github.com/ghodss/yaml
. This package uses the json
tags in the types as opposed to yaml
tags, which the upstream YAML package uses. Since we use the json
tags as well in the dyn
package it should be possible to replace it.
Not blocking for this PR, of course.
Co-authored-by: Pieter Noordhuis <[email protected]>
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.
Thanks, can you TAL at the PR summary before merging?
Changes
Added JSON input validation for CLI commands. Now when invalid JSON passed as a payload to CLI commands, CLI performs input normalisation and detects if there are any mismatches such as incorrect types, unknown fields and etc.
This diagnostic information is printed in standard error output and does not block command execution, so the change is backward compatible.
This PR also addresses issue when values which are considered "empty" in Go (such as
false
, 0, "" and etc.) were ignored and not passed to API request payload.Fixes #1769 #1764 #1625 #1560
Tests
Added unit tests