2018-09-03 10:08:03 +00:00
|
|
|
package webhooks
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
2018-09-10 10:01:38 +00:00
|
|
|
httperror "github.com/portainer/libhttp/error"
|
2019-03-21 01:20:14 +00:00
|
|
|
portainer "github.com/portainer/portainer/api"
|
|
|
|
"github.com/portainer/portainer/api/docker"
|
|
|
|
"github.com/portainer/portainer/api/http/security"
|
2018-09-03 10:08:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Handler is the HTTP handler used to handle webhook operations.
|
|
|
|
type Handler struct {
|
|
|
|
*mux.Router
|
2020-05-20 05:23:15 +00:00
|
|
|
DataStore portainer.DataStore
|
2018-09-03 10:08:03 +00:00
|
|
|
DockerClientFactory *docker.ClientFactory
|
|
|
|
}
|
|
|
|
|
2021-11-22 18:05:09 +00:00
|
|
|
// NewHandler creates a handler to manage webhooks operations.
|
2018-09-03 10:08:03 +00:00
|
|
|
func NewHandler(bouncer *security.RequestBouncer) *Handler {
|
|
|
|
h := &Handler{
|
|
|
|
Router: mux.NewRouter(),
|
|
|
|
}
|
|
|
|
h.Handle("/webhooks",
|
2019-10-07 03:10:51 +00:00
|
|
|
bouncer.AuthenticatedAccess(httperror.LoggerHandler(h.webhookCreate))).Methods(http.MethodPost)
|
2021-12-06 20:11:44 +00:00
|
|
|
h.Handle("/webhooks/{id}",
|
|
|
|
bouncer.AuthenticatedAccess(httperror.LoggerHandler(h.webhookUpdate))).Methods(http.MethodPut)
|
2018-09-03 10:08:03 +00:00
|
|
|
h.Handle("/webhooks",
|
2019-10-07 03:10:51 +00:00
|
|
|
bouncer.AuthenticatedAccess(httperror.LoggerHandler(h.webhookList))).Methods(http.MethodGet)
|
2018-09-03 10:08:03 +00:00
|
|
|
h.Handle("/webhooks/{id}",
|
2019-10-07 03:10:51 +00:00
|
|
|
bouncer.AuthenticatedAccess(httperror.LoggerHandler(h.webhookDelete))).Methods(http.MethodDelete)
|
2018-09-03 10:08:03 +00:00
|
|
|
h.Handle("/webhooks/{token}",
|
|
|
|
bouncer.PublicAccess(httperror.LoggerHandler(h.webhookExecute))).Methods(http.MethodPost)
|
|
|
|
return h
|
|
|
|
}
|