mirror of
https://github.com/portainer/portainer.git
synced 2025-07-19 05:19:39 +02:00
feat(webhook) EE-2125 send registry auth haeder when update swarms service via webhook (#6220)
* feat(webhook) EE-2125 add some helpers to registry utils * feat(webhook) EE-2125 persist registryID when creating a webhook * feat(webhook) EE-2125 send registry auth header when executing a webhook * feat(webhook) EE-2125 send registryID to backend when creating a service with webhook * feat(webhook) EE-2125 use the initial registry ID to create webhook on editing service screen * feat(webhook) EE-2125 update webhook when update registry * feat(webhook) EE-2125 add endpoint of update webhook * feat(webhook) EE-2125 code cleanup * feat(webhook) EE-2125 fix a typo * feat(webhook) EE-2125 fix circle import issue with unit test Co-authored-by: Simon Meng <simon.meng@portainer.io>
This commit is contained in:
parent
aa8fc52106
commit
98972dec0d
12 changed files with 254 additions and 8 deletions
|
@ -2,6 +2,8 @@ package webhooks
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/portainer/portainer/api/http/security"
|
||||
"github.com/portainer/portainer/api/internal/registryutils/access"
|
||||
"net/http"
|
||||
|
||||
"github.com/asaskevich/govalidator"
|
||||
|
@ -16,6 +18,7 @@ import (
|
|||
type webhookCreatePayload struct {
|
||||
ResourceID string
|
||||
EndpointID int
|
||||
RegistryID portainer.RegistryID
|
||||
WebhookType int
|
||||
}
|
||||
|
||||
|
@ -60,6 +63,20 @@ func (handler *Handler) webhookCreate(w http.ResponseWriter, r *http.Request) *h
|
|||
return &httperror.HandlerError{http.StatusConflict, "A webhook for this resource already exists", errors.New("A webhook for this resource already exists")}
|
||||
}
|
||||
|
||||
endpointID := portainer.EndpointID(payload.EndpointID)
|
||||
|
||||
if payload.RegistryID != 0 {
|
||||
tokenData, err := security.RetrieveTokenData(r)
|
||||
if err != nil {
|
||||
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve user authentication token", err}
|
||||
}
|
||||
|
||||
_, err = access.GetAccessibleRegistry(handler.DataStore, tokenData.ID, endpointID, payload.RegistryID)
|
||||
if err != nil {
|
||||
return &httperror.HandlerError{http.StatusForbidden, "Permission deny to access registry", err}
|
||||
}
|
||||
}
|
||||
|
||||
token, err := uuid.NewV4()
|
||||
if err != nil {
|
||||
return &httperror.HandlerError{http.StatusInternalServerError, "Error creating unique token", err}
|
||||
|
@ -68,7 +85,8 @@ func (handler *Handler) webhookCreate(w http.ResponseWriter, r *http.Request) *h
|
|||
webhook = &portainer.Webhook{
|
||||
Token: token.String(),
|
||||
ResourceID: payload.ResourceID,
|
||||
EndpointID: portainer.EndpointID(payload.EndpointID),
|
||||
EndpointID: endpointID,
|
||||
RegistryID: payload.RegistryID,
|
||||
WebhookType: portainer.WebhookType(payload.WebhookType),
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue