Skip to content

Commit

Permalink
fix: allow updating of webhooks without specifying secret
Browse files Browse the repository at this point in the history
Signed-off-by: Donnie Adams <[email protected]>
  • Loading branch information
thedadams committed Nov 21, 2024
1 parent 8ff27a0 commit 8af3b96
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions pkg/api/handlers/webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (a *WebhookHandler) Update(req api.Context) error {
return err
}

if err := validateManifest(req, webhookReq.WebhookManifest); err != nil {
if err := validateManifest(req, webhookReq.WebhookManifest, false); err != nil {
return err
}

Expand Down Expand Up @@ -96,7 +96,7 @@ func (a *WebhookHandler) Create(req api.Context) error {
return err
}

if err := validateManifest(req, webhookReq.WebhookManifest); err != nil {
if err := validateManifest(req, webhookReq.WebhookManifest, true); err != nil {
return err
}

Expand Down Expand Up @@ -278,7 +278,7 @@ func validateSecretHeader(secret string, body []byte, values []string) error {
return fmt.Errorf("invalid secret header")
}

func validateManifest(req api.Context, manifest types.WebhookManifest) error {
func validateManifest(req api.Context, manifest types.WebhookManifest, create bool) error {
// Ensure that the WorkflowID is set and the workflow exists
if manifest.Workflow == "" {
return apierrors.NewBadRequest("webhook manifest must have a workflow name")
Expand All @@ -291,7 +291,8 @@ func validateManifest(req api.Context, manifest types.WebhookManifest) error {
}
}

if (manifest.ValidationHeader != "") != (manifest.Secret != "") {
// On creation, the user must set both the validation header and secret or set neither.
if create && (manifest.ValidationHeader != "") != (manifest.Secret != "") {
return apierrors.NewBadRequest("webhook must have secret and header set together")
}

Expand Down

0 comments on commit 8af3b96

Please sign in to comment.