-
Notifications
You must be signed in to change notification settings - Fork 243
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
Add validation for parameters passed with command #3259
Add validation for parameters passed with command #3259
Conversation
43240e7
to
e431cda
Compare
Couple of things: $ odo config set ports "8080/TCP/UDP" -f
E0529 11:36:57.513401 6790 config.go:690] Validation failed for the provided arguments, Error: unable to parse the port string 8080/TCP/UDP
✗ unknown parameter :'' is not a parameter in local odo config IMO, we should simply print the error message. Details about error number, line where it occurred, etc. should not be shown to the user. Also, why is it showing the error IMO, below should fail because I've not provided TCP or UDP to port 9090: $ odo config set ports "8080/TCP,9090" -f
✓ Local config successfully updated
Run `odo push --config` command to apply changes to the cluster
$ odo config view
COMPONENT SETTINGS
------------------------------------------------
PARAMETER CURRENT_VALUE
Type nodejs
Application app
Project default
SourceType local
Ref
SourceLocation ./
Ports 8080/TCP,9090
Name nodejs-nodejs-ex-wcxj
MinMemory
MaxMemory
DebugPort
Ignore
MinCPU
MaxCPU Another thing from code point of view - please add a comment describing what |
d0c00bd
to
914d9c9
Compare
is not failing because the port validator function accepts it. I'm using existing validation utilities so that the validation behavior remains uniform. Should I create a different validator ? |
d74ba3f
to
5ad2ab2
Compare
Nope. My bad. Should have read the comments that said it's a valid value. |
If I remember correctly not providing the protocol in |
Behind the scenes, it does. I tried creating a URL for port without protocol info in |
I think it would help to be clear with the user if we specify that in |
Or, it could be mentioned in the CLI documentation or actual documentation. If we'd want to make it clear in the output of |
5ad2ab2
to
313fab9
Compare
pkg/config/config.go
Outdated
case "ports", "debugport": | ||
err = validation.PortsValidator(args[1]) | ||
default: | ||
if len(args) < 2 || len(args[1]) == 0 { |
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.
Shouldn’t this check be at the top?
pkg/config/config.go
Outdated
var err error | ||
switch param { | ||
case "ports", "debugport": | ||
err = validation.PortsValidator(args[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.
What would happen if I provided odo config set ports
without any value for the ports? Probably would panic due to args[1]
I guess
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.
pkg/config/config.go
Outdated
param, ok := asLocallySupportedParameter(args[0]) | ||
|
||
if !ok { | ||
return errors.Errorf("the parameter provided : %v, is not present in the supported parameters list.", args[0]) |
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.
There is an error string convention that error don’t start with capitals and doesn’t end with a fullstop
313fab9
to
eb44e8a
Compare
pkg/config/config.go
Outdated
param, ok := asLocallySupportedParameter(args[0]) | ||
|
||
if !ok { | ||
err = errors.Errorf("the parameter provided : %v, is not present in the supported parameters list", args[0]) |
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.
I would just say: "provided parameter '%v' is not a supported parameter"
pkg/config/config.go
Outdated
if !ok { | ||
err = errors.Errorf("the parameter provided : %v, is not present in the supported parameters list", args[0]) | ||
} else if len(args) < 2 || len(args[1]) == 0 { | ||
err = errors.Errorf("no argument provided for parameter %v", param) |
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.
"no value" instead of "argument"
pkg/config/config.go
Outdated
} | ||
|
||
if err != nil { | ||
err = errors.Errorf("validation failed for the provided arguments, Error: %v", err) |
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.
I would output error as "validation failed for the provided arguments: %v"
pkg/config/config.go
Outdated
@@ -730,3 +731,30 @@ func (lci *LocalConfigInfo) GetOSSourcePath() (path string, err error) { | |||
|
|||
return sourceOSPath, err | |||
} | |||
|
|||
// IsValidArgumentList validates the argument list for `odo config` command | |||
func IsValidArgumentList(args []string) 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.
This function should actually be merged with the Args
function that is passed to the command struct when it's created since otherwise the check on args length will never occur (as it's done in that function). Actually, there would be merits to check the args there instead of in Complete
… See: https://github.com/openshift/odo/blob/6bd0d73dc67e014e34f7e92a35dab26734163afc/pkg/odo/cli/config/set.go#L96-L103
@dev-gaur CI failing |
eb44e8a
to
5fcdb29
Compare
CI seem to fail but code is good hence, please fix the tests if need be. |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: girishramnani The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
5fcdb29
to
804be26
Compare
Codecov Report
@@ Coverage Diff @@
## master #3259 +/- ##
==========================================
+ Coverage 46.28% 46.45% +0.16%
==========================================
Files 112 112
Lines 11200 11237 +37
==========================================
+ Hits 5184 5220 +36
+ Misses 5518 5513 -5
- Partials 498 504 +6
Continue to review full report at Codecov.
|
/kind bug |
pkg/config/config.go
Outdated
err = errors.Errorf("the parameter provided : %v, is not supported", args[0]) | ||
} | ||
|
||
switch param { |
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.
+100, I feel happy when i see switch statement instead of multiple if else
pkg/config/config.go
Outdated
@@ -730,3 +731,31 @@ func (lci *LocalConfigInfo) GetOSSourcePath() (path string, err error) { | |||
|
|||
return sourceOSPath, err | |||
} | |||
|
|||
// IsValidArgumentList validates the argument list for `odo config` command | |||
func IsValidArgumentList(args []string) 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.
This function should not be in that file as it only deals with command-related code, not config-related functionality per se. My advice would be to put it with the set command and unexport it.
pkg/config/config.go
Outdated
param, ok := asLocallySupportedParameter(args[0]) | ||
|
||
if !ok { | ||
err = errors.Errorf("the parameter provided : %v, is not supported", args[0]) |
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.
The wording is awkward. See my previous comment on this topic.
pkg/config/config.go
Outdated
} | ||
|
||
var err error | ||
param, ok := asLocallySupportedParameter(args[0]) |
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.
Moving the enclosing function to the set command will require exporting this function.
@dev-gaur any update on the comments made by chris? |
804be26
to
d6bf379
Compare
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.
LGTM
/retest |
/retest Please review the full test history for this PR and help us cut down flakes. |
3 similar comments
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
kind bug
What does does this PR do / why we need it:
Adds Validation on parameters passed with
odo config set
commandsWhich issue(s) this PR fixes:
Fixes #3036