Skip to content

fix: normalize webhook endpoint URL before validation#999

Open
AdeshDeshmukh wants to merge 3 commits into
goharbor:mainfrom
AdeshDeshmukh:fix/normalize-webhook-endpoint-url
Open

fix: normalize webhook endpoint URL before validation#999
AdeshDeshmukh wants to merge 3 commits into
goharbor:mainfrom
AdeshDeshmukh:fix/normalize-webhook-endpoint-url

Conversation

@AdeshDeshmukh

Copy link
Copy Markdown

What

Webhook endpoint URLs are now normalized via utils.FormatUrl before
validation and storage, making webhook consistent with how registry
and scanner commands handle URLs.

Why

utils.FormatUrl and utils.ValidateURL serve different purposes:

  • FormatUrl normalizes input: prepends https:// if no scheme is
    present, trims trailing slashes
  • ValidateURL validates structure: checks the URL is well-formed

Registry and scanner commands always call both in order. Webhook
commands called only ValidateURL, meaning un-normalized URLs such
as example.com/webhook or https://example.com/webhook/ were
stored as-is in Harbor.

What Changed

Four entry points are fixed, following the exact pattern in
cmd/harbor/root/registry/create.go:

File Entry Point
cmd/harbor/root/webhook/create.go Non-interactive create
cmd/harbor/root/webhook/edit.go Non-interactive edit
pkg/views/webhook/create/view.go Interactive create form
pkg/views/webhook/edit/view.go Interactive edit form

4 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.go and edit.go. It also included
unrelated doc regeneration. This PR fixes all four entry points
with a minimal, focused diff.

How to Test

# Without scheme — should store https://example.com/webhook
harbor webhook create --endpoint-url example.com/webhook [flags]

# Trailing slash — should store https://example.com/webhook  
harbor webhook create --endpoint-url https://example.com/webhook/ [flags]

# Interactive form — same normalization applies
harbor webhook create
# enter: example.com/webhook when prompted

Copilot AI review requested due to automatic review settings June 15, 2026 14:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.FormatUrl and persist the formatted value in both interactive views and flag-based flows.
  • Validate formatted webhook URLs instead of raw user input.
  • Properly handle api.GetRobot errors when output-format export 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 thread cmd/harbor/root/webhook/create.go Outdated
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))
}
@AdeshDeshmukh AdeshDeshmukh force-pushed the fix/normalize-webhook-endpoint-url branch from 7f9aa39 to 3cf4461 Compare June 15, 2026 14:47
…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>
@AdeshDeshmukh AdeshDeshmukh force-pushed the fix/normalize-webhook-endpoint-url branch from 3cf4461 to 450784e Compare June 15, 2026 14:49
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.

[feature]: Standardize URL normalization across Webhook commands and views

2 participants