Skip to content

fix(user): harbor user elevate to handle empty responses#634

Merged
bupd merged 11 commits into
goharbor:mainfrom
vg006:fix/elevate
Mar 3, 2026
Merged

fix(user): harbor user elevate to handle empty responses#634
bupd merged 11 commits into
goharbor:mainfrom
vg006:fix/elevate

Conversation

@vg006

@vg006 vg006 commented Jan 23, 2026

Copy link
Copy Markdown
Contributor

Overview

Fixes #633

The elevate sub-command of the user command is updated to,

  1. Handle empty responses(payload with no user a/c details) from registry.
  2. Handle the errors and log them properly.

cc: @bupd @NucleoFusion

Preview

demo

@codecov

codecov Bot commented Jan 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 66 lines in your changes missing coverage. Please review.
✅ Project coverage is 7.23%. Comparing base (60ad0bd) to head (14f8003).
⚠️ Report is 103 commits behind head on main.

Files with missing lines Patch % Lines
cmd/harbor/root/user/elevate.go 0.00% 22 Missing ⚠️
pkg/utils/utils.go 0.00% 12 Missing ⚠️
pkg/views/user/select/view.go 0.00% 10 Missing ⚠️
pkg/prompt/prompt.go 0.00% 8 Missing ⚠️
cmd/harbor/root/user/password.go 0.00% 5 Missing ⚠️
pkg/views/styles.go 0.00% 5 Missing ⚠️
cmd/harbor/root/user/delete.go 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             main    #634      +/-   ##
=========================================
- Coverage   10.99%   7.23%   -3.76%     
=========================================
  Files         173     261      +88     
  Lines        8671   12923    +4252     
=========================================
- Hits          953     935      -18     
- Misses       7612   11880    +4268     
- Partials      106     108       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bupd bupd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vg006 looks like lint is failing. Please fix the ci.

Thanks

@bupd

bupd commented Jan 23, 2026

Copy link
Copy Markdown
Member

@vg006 fix lint and let me know

@vg006

vg006 commented Jan 23, 2026

Copy link
Copy Markdown
Contributor Author

@bupd
I just fixed the issue, tested and built locally.

demo

@bupd

bupd commented Jan 23, 2026

Copy link
Copy Markdown
Member

@vg006 curious what screenrecorder are you using here. to get the gifs.

@vg006

vg006 commented Jan 23, 2026

Copy link
Copy Markdown
Contributor Author

Btw I use Charm's vhs for recording the terminal sessions, mostly for CLI tool.
I define custom tape files to produce desired gifs, but you need to configure them at the end.

Just record, test and repeat, until you get it correctly 😄

@bupd bupd self-requested a review January 23, 2026 13:58

@qcserestipy qcserestipy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vg006 Thank you very much for taking up this issue! Could you explain why log.SetOutput(cmd.OutOrStderr()) is necessary here? This pattern isn't used anywhere else in the codebase, so I'm curious if there's a specific reason for it in this case.

@vg006

vg006 commented Feb 1, 2026

Copy link
Copy Markdown
Contributor Author

@qcserestipy As you can see here, the logger is set with io.Discard as a output writer in non-verbose mode, neither used os.StdOut nor os.StdErr writers.

So this silences the logrus. I agree that it is logged in the verbose mode, but normally a command should provide a proper closure upon the exit right. So I set it explicitly using the Cobra's writers within the command itself, instead of tweaking the global configuration.

@bupd bupd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution

@vg006 please fix the suggested changes

Comment thread cmd/harbor/root/user/delete.go Outdated
Comment thread pkg/utils/utils.go
@vg006

vg006 commented Feb 10, 2026

Copy link
Copy Markdown
Contributor Author

@bupd How about this change?

  1. Removed the log.SetOutput
  2. Update the logic to render a fancy message in case of no users.

Made with VHS

@vg006

vg006 commented Feb 13, 2026

Copy link
Copy Markdown
Contributor Author

I updated the output, but using existing styles in the project's views package.

Additionally just added a utility function RedText which returns the given string wrapped by ANSI sequences for Red color, using is too using the existing constants.

demo1

@qcserestipy

Copy link
Copy Markdown
Collaborator

@vg006 @bupd I think changing the styling and color for this command only is not really necessary. Since we return simple text in every other command it could be confusing that it is different here. Just returning the error message as text should be the simplest. I guess fmt.Errorf and fmt.Printf should be enough.

@vg006

vg006 commented Feb 14, 2026

Copy link
Copy Markdown
Contributor Author

I thought of improving the UX and I have just used the styles that are already defined in the project. Just added a utility function that returns the given text, wrapped by ANSI sequences.

Fine, then as per your suggestion, let me make this PR minimal.
But I will propose this type of styled messages in my ongoing work #635, which will have a good impression on the UI and improves usability.

Signed-off-by: vg006 <devvg006@gmail.com>
Signed-off-by: vg006 <devvg006@gmail.com>
Signed-off-by: vg006 <devvg006@gmail.com>
Signed-off-by: vg006 <devvg006@gmail.com>
Signed-off-by: vg006 <devvg006@gmail.com>
Signed-off-by: vg006 <devvg006@gmail.com>
Signed-off-by: vg006 <devvg006@gmail.com>
Signed-off-by: vg006 <devvg006@gmail.com>
@vg006

vg006 commented Feb 23, 2026

Copy link
Copy Markdown
Contributor Author

@qcserestipy I just updated the view, so that a line stating that "No users found in the registry" is printed simply, without any fancy view and ANSI sequences.

I have also update the command to return error (from Run to RunE). So now it will throw error in case of invalid operation or any failure and exit with a status code 1.

Preview

non-verbose

@bupd bupd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

Comment thread cmd/harbor/root/user/delete.go Outdated
Signed-off-by: vg006 <devvg006@gmail.com>
@vg006

vg006 commented Mar 3, 2026

Copy link
Copy Markdown
Contributor Author

@bupd @qcserestipy
The PR is updated as per the reviews and suggestions above and it is ready to merge.

@bupd bupd merged commit 1331aac into goharbor:main Mar 3, 2026
6 of 8 checks passed
@vg006 vg006 deleted the fix/elevate branch March 3, 2026 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

harbor user elevate executes even in absence of users

3 participants