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
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewHandler creates a handler to manage settings operations.
|
|
|
|
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)
|
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
|
|
|
|
}
|