docs(webhooks): document required endpoint and webhook type [EE-5286] (#8973)

pull/8989/head
Chaim Lev-Ari 2023-05-23 10:05:55 +07:00 committed by GitHub
parent 8acea44ee8
commit ef00350922
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 13 deletions

View File

@ -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)

View File

@ -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)
}

View File

@ -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"`
}