OADP-7955: Hides --namespace flag from nonadmin commands#194
OADP-7955: Hides --namespace flag from nonadmin commands#194NicholasYancey wants to merge 6 commits into
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: NicholasYancey The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds a local ChangesNonadmin namespace flag hiding
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cmd/root.go`:
- Around line 517-519: The code currently unconditionally restores flag.Hidden
to false in the defer, which can expose a flag that was originally hidden;
capture the original state before mutating (e.g., save originalHidden :=
flag.Hidden after Lookup("namespace")), set flag.Hidden = true, and in the defer
restore flag.Hidden = originalHidden so the flag's prior visibility (from the
flag returned by c.InheritedFlags().Lookup("namespace")) is preserved.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
mpryc
left a comment
There was a problem hiding this comment.
This PR is not wrong, but it does just hide the command and not prevent non-admin user to pass the --namespace, a much better fix would be to reject it with an error in a PersistentPreRunE on the nonadmin command, e.g.:
nonadminCmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
if cmd.Flags().Changed("namespace") {
return fmt.Errorf("--namespace is not supported for nonadmin commands; namespace is determined by your current context")
}
return nil
}
I agree w/ @mpryc |
|
@NicholasYancey: This pull request references OADP-7955 which is a valid jira issue. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
|
@NicholasYancey note, to link pr's to jira if there is a jira :) .. Per branch |
Why the changes were made
The
--namespaceflag was appearing in the help section for all nonadmin commands, but was silently ignored. If the user tried to use the-n, --namespaceunder a NAB, the flag was ignored. The user should not be able to see flags that they cannot use in that context which is why I chose to hide the flag from the user.How to test the changes made
Verify the namespace flag is hidden from nonadmin commands: