fix: normalize webhook endpoint URL before validation#999
Open
AdeshDeshmukh wants to merge 3 commits into
Open
fix: normalize webhook endpoint URL before validation#999AdeshDeshmukh wants to merge 3 commits into
AdeshDeshmukh wants to merge 3 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Normalizes webhook endpoint URLs before validation/submit and stops ignoring errors when exporting robot details.
Changes:
- Format webhook endpoint URLs via
utils.FormatUrland persist the formatted value in both interactive views and flag-based flows. - Validate formatted webhook URLs instead of raw user input.
- Properly handle
api.GetRoboterrors whenoutput-formatexport is requested.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/views/webhook/edit/view.go | Formats endpoint URL and saves formatted value during interactive edit validation. |
| pkg/views/webhook/create/view.go | Formats endpoint URL and saves formatted value during interactive create validation. |
| cmd/harbor/root/webhook/edit.go | Formats and validates endpoint URL before updating via non-interactive flags. |
| cmd/harbor/root/webhook/create.go | Formats and validates endpoint URL before creating via non-interactive flags. |
| cmd/harbor/root/robot/update.go | Returns a surfaced error if fetching robot details for export fails. |
| cmd/harbor/root/robot/create.go | Returns a surfaced error if fetching robot details for export fails. |
| cmd/harbor/root/project/robot/create.go | Returns a surfaced error if fetching robot details for export fails. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
109
to
+116
| if strings.TrimSpace(str) == "" { | ||
| return errors.New("endpoint URL cannot be empty") | ||
| } | ||
| if err := utils.ValidateURL(str); err != nil { | ||
| formattedUrl := utils.FormatUrl(str) | ||
| if err := utils.ValidateURL(formattedUrl); err != nil { | ||
| return err | ||
| } | ||
| editView.EndpointURL = formattedUrl |
Comment on lines
+86
to
+91
| formattedUrl := utils.FormatUrl(str) | ||
| if err := utils.ValidateURL(formattedUrl); err != nil { | ||
| return err | ||
| } | ||
| createView.EndpointURL = formattedUrl | ||
| return nil |
Comment on lines
+72
to
+77
| formattedUrl := utils.FormatUrl(opts.EndpointURL) | ||
| err = utils.ValidateURL(formattedUrl) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| opts.EndpointURL = formattedUrl |
Comment on lines
+590
to
+593
| res, err := api.GetRobot(opts.ID) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to get robot details: %v", utils.ParseHarborErrorMsg(err)) | ||
| } |
7f9aa39 to
3cf4461
Compare
…prevent nil panic Signed-off-by: AdeshDeshmukh <adeshkd123@gmail.com> Signed-off-by: Adesh Deshmukh <adeshkd123@gmail.com>
Signed-off-by: Adesh Deshmukh <adeshkd123@gmail.com>
Apply FormatUrl before ValidateURL in the webhook interactive form validation callbacks, matching the pattern already used by registry and scanner commands for interactive input. The CLI flag path (create.go, edit.go) was already fixed upstream; this completes the fix for the interactive prompt path. Closes goharbor#828 Signed-off-by: Adesh Deshmukh <adeshkd123@gmail.com>
3cf4461 to
450784e
Compare
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.
What
Webhook endpoint URLs are now normalized via
utils.FormatUrlbeforevalidation and storage, making webhook consistent with how registry
and scanner commands handle URLs.
Why
utils.FormatUrlandutils.ValidateURLserve different purposes:FormatUrlnormalizes input: prependshttps://if no scheme ispresent, trims trailing slashes
ValidateURLvalidates structure: checks the URL is well-formedRegistry and scanner commands always call both in order. Webhook
commands called only
ValidateURL, meaning un-normalized URLs suchas
example.com/webhookorhttps://example.com/webhook/werestored as-is in Harbor.
What Changed
Four entry points are fixed, following the exact pattern in
cmd/harbor/root/registry/create.go:cmd/harbor/root/webhook/create.gocmd/harbor/root/webhook/edit.gopkg/views/webhook/create/view.gopkg/views/webhook/edit/view.go4 files, ~14 lines changed, no new imports, no new dependencies.
Difference from PR #829
PR #829 only modified the two interactive view files and missed the
CLI flag paths in
create.goandedit.go. It also includedunrelated doc regeneration. This PR fixes all four entry points
with a minimal, focused diff.
How to Test