Repository navigation
fix: unify webhook listeners on path based endpoints #304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Skarlso
merged 8 commits into
external-secrets:main
from
pepordev:fix/unify-webhook-listeners
Aug 15, 2026
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f493850
fix: unify webhook listeners on path based endpoints
pepordev 8eb7d1d
fix: Bump go to 1.26.2 to avoid stdlib CVEs
pepordev 1769c00
Merge branch 'main' into fix/unify-webhook-listeners
pepordev 592079e
fix: correct review findings
pepordev c4cb88b
fix: correct linting
pepordev c793353
Merge branch 'external-secrets:main' into fix/unify-webhook-listeners
pepordev 4117d82
feat: fix review comments
pepordev b56dbba
Merge branch 'fix/unify-webhook-listeners' of github.com:pepordev/rel…
pepordev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| package v1alpha1 | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "strings" | ||
| ) | ||
|
|
||
| const webhookNotificationSourceType = "Webhook" | ||
|
|
||
| // Validate checks cross-field constraints on ConfigSpec that cannot be expressed on individual fields. | ||
| func (s *ConfigSpec) Validate() error { | ||
| if err := validateUniqueWebhookPathSuffixes(s.NotificationSources); err != nil { | ||
| return err | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func validateUniqueWebhookPathSuffixes(sources []NotificationSource) error { | ||
| seen := map[string]int{} | ||
| var duplicates []string | ||
|
|
||
| for i, source := range sources { | ||
| if source.Type != webhookNotificationSourceType { | ||
| continue | ||
| } | ||
|
|
||
| suffix := "" | ||
| if source.Webhook != nil { | ||
| suffix = strings.TrimSpace(source.Webhook.PathSuffix) | ||
| } | ||
|
|
||
| if firstIndex, exists := seen[suffix]; exists { | ||
| if suffix == "" { | ||
| duplicates = append(duplicates, fmt.Sprintf( | ||
| "notificationSources[%d] and notificationSources[%d] both omit webhook.pathSuffix; at most one webhook without pathSuffix is allowed", | ||
| firstIndex, i, | ||
| )) | ||
| } else { | ||
| duplicates = append(duplicates, fmt.Sprintf( | ||
| "notificationSources[%d].webhook.pathSuffix %q duplicates notificationSources[%d].webhook.pathSuffix", | ||
| i, suffix, firstIndex, | ||
| )) | ||
| } | ||
| continue | ||
| } | ||
| seen[suffix] = i | ||
| } | ||
|
|
||
| if len(duplicates) == 0 { | ||
| return nil | ||
| } | ||
| return fmt.Errorf("%s", strings.Join(duplicates, "; ")) | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| package v1alpha1 | ||
|
|
||
| import "testing" | ||
|
|
||
| func TestConfigSpecValidate_UniqueWebhookPathSuffixes(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| spec ConfigSpec | ||
| wantErr bool | ||
| }{ | ||
| { | ||
| name: "single webhook without pathSuffix", | ||
| spec: ConfigSpec{ | ||
| NotificationSources: []NotificationSource{{ | ||
| Type: webhookNotificationSourceType, | ||
| Webhook: &WebhookConfig{}, | ||
| }}, | ||
| }, | ||
| }, | ||
| { | ||
| name: "multiple webhooks with distinct pathSuffixes", | ||
| spec: ConfigSpec{ | ||
| NotificationSources: []NotificationSource{ | ||
| { | ||
| Type: webhookNotificationSourceType, | ||
| Webhook: &WebhookConfig{PathSuffix: "vendor-a"}, | ||
| }, | ||
| { | ||
| Type: webhookNotificationSourceType, | ||
| Webhook: &WebhookConfig{PathSuffix: "vendor-b"}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| name: "one empty and one distinct pathSuffix", | ||
| spec: ConfigSpec{ | ||
| NotificationSources: []NotificationSource{ | ||
| { | ||
| Type: webhookNotificationSourceType, | ||
| Webhook: &WebhookConfig{}, | ||
| }, | ||
| { | ||
| Type: webhookNotificationSourceType, | ||
| Webhook: &WebhookConfig{PathSuffix: "vendor-a"}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| name: "multiple webhooks without pathSuffix", | ||
| spec: ConfigSpec{ | ||
| NotificationSources: []NotificationSource{ | ||
| { | ||
| Type: webhookNotificationSourceType, | ||
| Webhook: &WebhookConfig{}, | ||
| }, | ||
| { | ||
| Type: webhookNotificationSourceType, | ||
| Webhook: &WebhookConfig{}, | ||
| }, | ||
| }, | ||
| }, | ||
| wantErr: true, | ||
| }, | ||
| { | ||
| name: "multiple webhooks with nil webhook block", | ||
| spec: ConfigSpec{ | ||
| NotificationSources: []NotificationSource{ | ||
| {Type: webhookNotificationSourceType}, | ||
| {Type: webhookNotificationSourceType}, | ||
| }, | ||
| }, | ||
| wantErr: true, | ||
| }, | ||
| { | ||
| name: "duplicate pathSuffix", | ||
| spec: ConfigSpec{ | ||
| NotificationSources: []NotificationSource{ | ||
| { | ||
| Type: webhookNotificationSourceType, | ||
| Webhook: &WebhookConfig{PathSuffix: "vendor-a"}, | ||
| }, | ||
| { | ||
| Type: webhookNotificationSourceType, | ||
| Webhook: &WebhookConfig{PathSuffix: "vendor-a"}, | ||
| }, | ||
| }, | ||
| }, | ||
| wantErr: true, | ||
| }, | ||
| { | ||
| name: "duplicate pathSuffix ignores non-webhook sources", | ||
| spec: ConfigSpec{ | ||
| NotificationSources: []NotificationSource{ | ||
| { | ||
| Type: webhookNotificationSourceType, | ||
| Webhook: &WebhookConfig{PathSuffix: "vendor-a"}, | ||
| }, | ||
| { | ||
| Type: "TCPSocket", | ||
| TCPSocket: &TCPSocketConfig{ | ||
| Host: "127.0.0.1", | ||
| Port: 8000, | ||
| }, | ||
| }, | ||
| { | ||
| Type: webhookNotificationSourceType, | ||
| Webhook: &WebhookConfig{PathSuffix: "vendor-a"}, | ||
| }, | ||
| }, | ||
| }, | ||
| wantErr: true, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| t.Parallel() | ||
| err := tt.spec.Validate() | ||
| if tt.wantErr && err == nil { | ||
| t.Fatal("expected validation error") | ||
| } | ||
| if !tt.wantErr && err != nil { | ||
| t.Fatalf("unexpected validation error: %v", err) | ||
| } | ||
| }) | ||
| } | ||
| } |
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.