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
Fix args check for role and scc modify #6868
Conversation
This patch fixes following go panic.
|
@@ -226,7 +226,9 @@ func NewCmdRemoveClusterRoleFromUser(name, fullName string, f *clientcmd.Factory | |||
} | |||
|
|||
func (o *RoleModificationOptions) CompleteUserWithSA(f *clientcmd.Factory, args []string, saNames []string) error { | |||
if (len(args) < 2) && (len(saNames) == 0) { | |||
if (len(args) < 1) && (len(saNames) == 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.
I'd rather see:
if len(args) < 1 {
return errors.New("you must specify a role")
}
if (len(args) < 2) && (len(saNames) == 0) {
return errors.New("you must specify a user or a service account")
}
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.
and actually, put the if (len(args) < 2) && (len(saNames) == 0)
check after we've appended args[1:]
to o.Users
and check if (len(o.Users) == 0) && (len(saNames) == 0)
instead
Add tests to |
@liggitt Thank you. I updated. |
@@ -235,6 +235,10 @@ func (o *RoleModificationOptions) CompleteUserWithSA(f *clientcmd.Factory, args | |||
o.Users = append(o.Users, args[1:]...) | |||
} | |||
|
|||
if (len(o.Users) == 0) && (len(saNames) == 0) { | |||
return errors.New("you must specify at least two arguments: <role> <user> [user]...") |
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.
...at least one user or service account
Sorry, it was my mistake. I updated. |
Although it might be better to update the |
sure, go ahead and update the example text while we're in here |
(don't forget to regen the docs to pick up the new example) |
OK, I updated. |
Use: name + " ROLE (USER | -z SERVICEACCOUNT) [USER ...]", | ||
Short: "Add users or serviceaccount to a role in the current project", | ||
Long: `Add users or serviceaccount to a role in the current project`, | ||
Example: fmt.Sprintf(addRoleToUserExample, fullName), |
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.
"service accounts"
Thank you again. I updated. The |
os::cmd::expect_failure_and_text 'oc policy add-role-to-user' 'you must specify a role' | ||
os::cmd::expect_failure_and_text 'oc policy add-role-to-user -z NamespaceWithoutRole' 'you must specify a role' | ||
os::cmd::expect_failure_and_text 'oc policy add-role-to-user view' 'you must specify at least two arguments' | ||
|
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.
Didn't the error message change here?
Sorry! I updated. |
[test] |
Evaluated for origin test up to 51e0f8a |
continuous-integration/openshift-jenkins/test FAILURE (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/743/) |
LGTM, [merge] |
continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/merge_pull_requests_origin/4857/) (Image: devenv-rhel7_3339) |
Evaluated for origin merge up to 51e0f8a |
No description provided.