From ef00350922adf4ea1fbd8cc55204e596cdb9ae70 Mon Sep 17 00:00:00 2001 From: Chaim Lev-Ari Date: Tue, 23 May 2023 10:05:55 +0700 Subject: [PATCH] docs(webhooks): document required endpoint and webhook type [EE-5286] (#8973) --- api/http/handler/webhooks/webhook_create.go | 15 ++++++++------- api/http/handler/webhooks/webhook_list.go | 3 ++- api/portainer.go | 11 ++++++----- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/api/http/handler/webhooks/webhook_create.go b/api/http/handler/webhooks/webhook_create.go index 2d0e66548..9e27e4a34 100644 --- a/api/http/handler/webhooks/webhook_create.go +++ b/api/http/handler/webhooks/webhook_create.go @@ -17,10 +17,11 @@ import ( ) type webhookCreatePayload struct { - ResourceID string - EndpointID int - RegistryID portainer.RegistryID - WebhookType int + ResourceID string + EndpointID portainer.EndpointID + RegistryID portainer.RegistryID + // Type of webhook (1 - service) + WebhookType portainer.WebhookType } func (payload *webhookCreatePayload) Validate(r *http.Request) error { @@ -30,7 +31,7 @@ func (payload *webhookCreatePayload) Validate(r *http.Request) error { if payload.EndpointID == 0 { return errors.New("Invalid EndpointID") } - if payload.WebhookType != 1 { + if payload.WebhookType != portainer.ServiceWebhook { return errors.New("Invalid WebhookType") } return nil @@ -64,7 +65,7 @@ func (handler *Handler) webhookCreate(w http.ResponseWriter, r *http.Request) *h return &httperror.HandlerError{StatusCode: http.StatusConflict, Message: "A webhook for this resource already exists", Err: errors.New("A webhook for this resource already exists")} } - endpointID := portainer.EndpointID(payload.EndpointID) + endpointID := payload.EndpointID securityContext, err := security.RetrieveRestrictedRequestContext(r) if err != nil { @@ -97,7 +98,7 @@ func (handler *Handler) webhookCreate(w http.ResponseWriter, r *http.Request) *h ResourceID: payload.ResourceID, EndpointID: endpointID, RegistryID: payload.RegistryID, - WebhookType: portainer.WebhookType(payload.WebhookType), + WebhookType: payload.WebhookType, } err = handler.DataStore.Webhook().Create(webhook) diff --git a/api/http/handler/webhooks/webhook_list.go b/api/http/handler/webhooks/webhook_list.go index c2097a47d..653e38895 100644 --- a/api/http/handler/webhooks/webhook_list.go +++ b/api/http/handler/webhooks/webhook_list.go @@ -44,11 +44,12 @@ func (handler *Handler) webhookList(w http.ResponseWriter, r *http.Request) *htt } webhooks, err := handler.DataStore.Webhook().Webhooks() - webhooks = filterWebhooks(webhooks, &filters) if err != nil { return httperror.InternalServerError("Unable to retrieve webhooks from the database", err) } + webhooks = filterWebhooks(webhooks, &filters) + return response.JSON(w, webhooks) } diff --git a/api/portainer.go b/api/portainer.go index 2e521ca13..72afb6c32 100644 --- a/api/portainer.go +++ b/api/portainer.go @@ -1306,11 +1306,12 @@ type ( // Webhook represents a url webhook that can be used to update a service Webhook struct { // Webhook Identifier - ID WebhookID `json:"Id" example:"1"` - Token string `json:"Token"` - ResourceID string `json:"ResourceId"` - EndpointID EndpointID `json:"EndpointId"` - RegistryID RegistryID `json:"RegistryId"` + ID WebhookID `json:"Id" example:"1"` + Token string `json:"Token"` + ResourceID string `json:"ResourceId"` + EndpointID EndpointID `json:"EndpointId"` + RegistryID RegistryID `json:"RegistryId"` + // Type of webhook (1 - service) WebhookType WebhookType `json:"Type"` }