mirror of https://github.com/portainer/portainer
docs(webhooks): document required endpoint and webhook type [EE-5286] (#8973)
parent
8acea44ee8
commit
ef00350922
|
@ -17,10 +17,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type webhookCreatePayload struct {
|
type webhookCreatePayload struct {
|
||||||
ResourceID string
|
ResourceID string
|
||||||
EndpointID int
|
EndpointID portainer.EndpointID
|
||||||
RegistryID portainer.RegistryID
|
RegistryID portainer.RegistryID
|
||||||
WebhookType int
|
// Type of webhook (1 - service)
|
||||||
|
WebhookType portainer.WebhookType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (payload *webhookCreatePayload) Validate(r *http.Request) error {
|
func (payload *webhookCreatePayload) Validate(r *http.Request) error {
|
||||||
|
@ -30,7 +31,7 @@ func (payload *webhookCreatePayload) Validate(r *http.Request) error {
|
||||||
if payload.EndpointID == 0 {
|
if payload.EndpointID == 0 {
|
||||||
return errors.New("Invalid EndpointID")
|
return errors.New("Invalid EndpointID")
|
||||||
}
|
}
|
||||||
if payload.WebhookType != 1 {
|
if payload.WebhookType != portainer.ServiceWebhook {
|
||||||
return errors.New("Invalid WebhookType")
|
return errors.New("Invalid WebhookType")
|
||||||
}
|
}
|
||||||
return nil
|
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")}
|
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)
|
securityContext, err := security.RetrieveRestrictedRequestContext(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -97,7 +98,7 @@ func (handler *Handler) webhookCreate(w http.ResponseWriter, r *http.Request) *h
|
||||||
ResourceID: payload.ResourceID,
|
ResourceID: payload.ResourceID,
|
||||||
EndpointID: endpointID,
|
EndpointID: endpointID,
|
||||||
RegistryID: payload.RegistryID,
|
RegistryID: payload.RegistryID,
|
||||||
WebhookType: portainer.WebhookType(payload.WebhookType),
|
WebhookType: payload.WebhookType,
|
||||||
}
|
}
|
||||||
|
|
||||||
err = handler.DataStore.Webhook().Create(webhook)
|
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, err := handler.DataStore.Webhook().Webhooks()
|
||||||
webhooks = filterWebhooks(webhooks, &filters)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return httperror.InternalServerError("Unable to retrieve webhooks from the database", err)
|
return httperror.InternalServerError("Unable to retrieve webhooks from the database", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
webhooks = filterWebhooks(webhooks, &filters)
|
||||||
|
|
||||||
return response.JSON(w, webhooks)
|
return response.JSON(w, webhooks)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1306,11 +1306,12 @@ type (
|
||||||
// Webhook represents a url webhook that can be used to update a service
|
// Webhook represents a url webhook that can be used to update a service
|
||||||
Webhook struct {
|
Webhook struct {
|
||||||
// Webhook Identifier
|
// Webhook Identifier
|
||||||
ID WebhookID `json:"Id" example:"1"`
|
ID WebhookID `json:"Id" example:"1"`
|
||||||
Token string `json:"Token"`
|
Token string `json:"Token"`
|
||||||
ResourceID string `json:"ResourceId"`
|
ResourceID string `json:"ResourceId"`
|
||||||
EndpointID EndpointID `json:"EndpointId"`
|
EndpointID EndpointID `json:"EndpointId"`
|
||||||
RegistryID RegistryID `json:"RegistryId"`
|
RegistryID RegistryID `json:"RegistryId"`
|
||||||
|
// Type of webhook (1 - service)
|
||||||
WebhookType WebhookType `json:"Type"`
|
WebhookType WebhookType `json:"Type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue