1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-22 06:49:40 +02:00

feat(api): introduce new datastore interface (#3802)

* feat(api): introduce new datastore interface

* refactor(api): refactor http and main layers

* refactor(api): refactor http and bolt layers
This commit is contained in:
Anthony Lapenna 2020-05-20 17:23:15 +12:00 committed by Anthony Lapenna
parent 493de20540
commit 25103f08f9
151 changed files with 792 additions and 1004 deletions

View file

@ -13,8 +13,7 @@ import (
// Handler is the HTTP handler used to handle webhook operations.
type Handler struct {
*mux.Router
WebhookService portainer.WebhookService
EndpointService portainer.EndpointService
DataStore portainer.DataStore
DockerClientFactory *docker.ClientFactory
}

View file

@ -37,7 +37,7 @@ func (handler *Handler) webhookCreate(w http.ResponseWriter, r *http.Request) *h
return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err}
}
webhook, err := handler.WebhookService.WebhookByResourceID(payload.ResourceID)
webhook, err := handler.DataStore.Webhook().WebhookByResourceID(payload.ResourceID)
if err != nil && err != portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusInternalServerError, "An error occurred retrieving webhooks from the database", err}
}
@ -57,7 +57,7 @@ func (handler *Handler) webhookCreate(w http.ResponseWriter, r *http.Request) *h
WebhookType: portainer.WebhookType(payload.WebhookType),
}
err = handler.WebhookService.CreateWebhook(webhook)
err = handler.DataStore.Webhook().CreateWebhook(webhook)
if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist the webhook inside the database", err}
}

View file

@ -16,7 +16,7 @@ func (handler *Handler) webhookDelete(w http.ResponseWriter, r *http.Request) *h
return &httperror.HandlerError{http.StatusBadRequest, "Invalid webhook id", err}
}
err = handler.WebhookService.DeleteWebhook(portainer.WebhookID(id))
err = handler.DataStore.Webhook().DeleteWebhook(portainer.WebhookID(id))
if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to remove the webhook from the database", err}
}

View file

@ -21,7 +21,7 @@ func (handler *Handler) webhookExecute(w http.ResponseWriter, r *http.Request) *
return &httperror.HandlerError{http.StatusInternalServerError, "Invalid service id parameter", err}
}
webhook, err := handler.WebhookService.WebhookByToken(webhookToken)
webhook, err := handler.DataStore.Webhook().WebhookByToken(webhookToken)
if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find a webhook with this token", err}
@ -33,7 +33,7 @@ func (handler *Handler) webhookExecute(w http.ResponseWriter, r *http.Request) *
endpointID := webhook.EndpointID
webhookType := webhook.WebhookType
endpoint, err := handler.EndpointService.Endpoint(portainer.EndpointID(endpointID))
endpoint, err := handler.DataStore.Endpoint().Endpoint(portainer.EndpointID(endpointID))
if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find an endpoint with the specified identifier inside the database", err}
} else if err != nil {

View file

@ -22,7 +22,7 @@ func (handler *Handler) webhookList(w http.ResponseWriter, r *http.Request) *htt
return &httperror.HandlerError{http.StatusBadRequest, "Invalid query parameter: filters", err}
}
webhooks, err := handler.WebhookService.Webhooks()
webhooks, err := handler.DataStore.Webhook().Webhooks()
webhooks = filterWebhooks(webhooks, &filters)
if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve webhooks from the database", err}