fix(member): use canonical Harbor role IDs and surface API errors#908
Open
dev-aditya-hub wants to merge 1 commit into
Open
fix(member): use canonical Harbor role IDs and surface API errors#908dev-aditya-hub wants to merge 1 commit into
dev-aditya-hub wants to merge 1 commit into
Conversation
Signed-off-by: Aditya@8767 <premjadhvar95@gmail.com>
3fb9fb4 to
71f2ccd
Compare
Author
|
Hi @qcserestipy, when you have a moment, could you take a look at this PR? Short version of the bug: The PR makes the canonical Harbor role ID (1..5) the only representation past the cobra layer, validates Thanks! |
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
While testing
harbor project member create, I noticed--roleid 1was creating a Developer instead of a Project Admin, and a failing API call still printedsuccessfully added user .... Tracing it, the role ID had two different representations in the codebase and one of them was being silently shifted.This PR makes the Harbor role ID (1=Admin..5=LimitedGuest) the only representation past the cobra layer.
Changes
pkg/api/member_handler.go: drop the+1shift inCreateMember; the wrapper now passesRoleIDthrough unchanged.pkg/views/member/create/view.go: bind the interactive role select directly to the existingRoleOptionsmap (1..5) instead of slice indices (0..4), so the form and the flags share one representation.cmd/harbor/root/project/member/create.go:resolveRoleFlagsto normalize--roleand--roleidinto a single canonical ID, with explicit validation and conflict detection (previously--rolewas registered but never resolved).GetSystemInfoandCreateMemberinstead of logging them and falling through to the success message.Behavior
--roleid 1--role Developer--role Foo--role Admin --roleid 3Test plan
harbor project member create <p> --username <u> --roleid 1creates a Project Adminharbor project member create <p> --username <u> --role Developercreates a Developerharbor project member create <p> --username <u> --role Foofails with a clear message