docs(webhooks): document required endpoint and webhook type [EE-5286] (#8973)
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user