fix(serviceaccount reset-credentials): validate serviceaccount ID in prompt#720
fix(serviceaccount reset-credentials): validate serviceaccount ID in prompt#720rkpattnaik780 merged 3 commits intodevelopfrom
Conversation
|
Should client side validation be extended to non-interactive mode as well? Also, it seems bit complex to write tests for higher order functions being used as validators. |
craicoverflow
left a comment
There was a problem hiding this comment.
Should client side validation be extended to non-interactive mode as well?
Yes, we should. Any client-side validation improves UX/DX so this would be nice to have.
Also, it seems bit complex to write tests for higher order functions being used as validators.
Yeah, I see what you mean! Now that we are needing to pass localizer to validators they are no longer simple functions.
What would be better (and you can do this in this PR) is to create a Validator type which contains all the validator functions for service accounts.
| } | ||
|
|
||
| // ValidateID validates if ID is a valid UUID | ||
| func ValidateID(localizer localize.Localizer) func(v interface{}) error { |
There was a problem hiding this comment.
| func ValidateID(localizer localize.Localizer) func(v interface{}) error { | |
| func ValidateUUID(localizer localize.Localizer) func(v interface{}) error { |
| legalNameChars = "^[a-z]([-a-z0-9]*[a-z0-9])?$" | ||
| maxNameLength = 50 | ||
| minNameLength = 1 | ||
| leagalUUID = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$" |
There was a problem hiding this comment.
| leagalUUID = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$" | |
| legalUUID = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$" |
| } | ||
|
|
||
| // ValidateUUID validates if ID is a valid UUID | ||
| func ValidateUUID(localizer localize.Localizer) func(v interface{}) error { |
There was a problem hiding this comment.
I think it will be a good idea for readibility if we do not use anonymous return functions anymore for all validators. I'll explain in a follow up issue
There was a problem hiding this comment.
PS: It would also be nice to validate the flag for UUId like you had suggested.
It has been done in reset_credentials.go. Did you expect something else?
There was a problem hiding this comment.
I think it will be a good idea for readibility if we do not use anonymous return functions anymore for all validators. I'll explain in a follow up issue
Maked #721 as WIP, it has localizations for validators using anonymous functions, should this PR wait for the issue?
There was a problem hiding this comment.
Ah I had not installed the binary :)
There was a problem hiding this comment.
No you can merge this PR beforehand if you like.
| } | ||
| } | ||
|
|
||
| func TestValidateUUID(t *testing.T) { |
|
PS: It would also be nice to validate the flag for UUId like you had suggested. |
Client side validation for service account ID in interactive mode.
Closes #716
Verification Steps
"kafka". It should throw the error:Type of change
Checklist