2018-06-11 13:13:19 +00:00
|
|
|
package endpoints
|
|
|
|
|
|
|
|
import (
|
2018-09-10 10:01:38 +00:00
|
|
|
httperror "github.com/portainer/libhttp/error"
|
2018-06-11 13:13:19 +00:00
|
|
|
"github.com/portainer/portainer"
|
|
|
|
"github.com/portainer/portainer/http/proxy"
|
|
|
|
"github.com/portainer/portainer/http/security"
|
|
|
|
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
// ErrEndpointManagementDisabled is an error raised when trying to access the endpoints management endpoints
|
|
|
|
// when the server has been started with the --external-endpoints flag
|
|
|
|
ErrEndpointManagementDisabled = portainer.Error("Endpoint management is disabled")
|
|
|
|
)
|
|
|
|
|
|
|
|
func hideFields(endpoint *portainer.Endpoint) {
|
|
|
|
endpoint.AzureCredentials = portainer.AzureCredentials{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handler is the HTTP handler used to handle endpoint operations.
|
|
|
|
type Handler struct {
|
|
|
|
*mux.Router
|
|
|
|
authorizeEndpointManagement bool
|
2018-07-25 18:47:33 +00:00
|
|
|
requestBouncer *security.RequestBouncer
|
2018-06-11 13:13:19 +00:00
|
|
|
EndpointService portainer.EndpointService
|
|
|
|
EndpointGroupService portainer.EndpointGroupService
|
|
|
|
FileService portainer.FileService
|
|
|
|
ProxyManager *proxy.Manager
|
2018-07-23 07:51:33 +00:00
|
|
|
Snapshotter portainer.Snapshotter
|
2018-10-22 21:03:30 +00:00
|
|
|
JobService portainer.JobService
|
2018-06-11 13:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewHandler creates a handler to manage endpoint operations.
|
|
|
|
func NewHandler(bouncer *security.RequestBouncer, authorizeEndpointManagement bool) *Handler {
|
|
|
|
h := &Handler{
|
|
|
|
Router: mux.NewRouter(),
|
|
|
|
authorizeEndpointManagement: authorizeEndpointManagement,
|
2018-07-25 18:47:33 +00:00
|
|
|
requestBouncer: bouncer,
|
2018-06-11 13:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
h.Handle("/endpoints",
|
|
|
|
bouncer.AdministratorAccess(httperror.LoggerHandler(h.endpointCreate))).Methods(http.MethodPost)
|
2018-07-25 19:52:17 +00:00
|
|
|
h.Handle("/endpoints/snapshot",
|
2018-11-13 03:02:49 +00:00
|
|
|
bouncer.AdministratorAccess(httperror.LoggerHandler(h.endpointSnapshots))).Methods(http.MethodPost)
|
2018-06-11 13:13:19 +00:00
|
|
|
h.Handle("/endpoints",
|
|
|
|
bouncer.RestrictedAccess(httperror.LoggerHandler(h.endpointList))).Methods(http.MethodGet)
|
|
|
|
h.Handle("/endpoints/{id}",
|
2018-07-25 18:47:33 +00:00
|
|
|
bouncer.RestrictedAccess(httperror.LoggerHandler(h.endpointInspect))).Methods(http.MethodGet)
|
2018-06-11 13:13:19 +00:00
|
|
|
h.Handle("/endpoints/{id}",
|
|
|
|
bouncer.AdministratorAccess(httperror.LoggerHandler(h.endpointUpdate))).Methods(http.MethodPut)
|
|
|
|
h.Handle("/endpoints/{id}/access",
|
|
|
|
bouncer.AdministratorAccess(httperror.LoggerHandler(h.endpointUpdateAccess))).Methods(http.MethodPut)
|
|
|
|
h.Handle("/endpoints/{id}",
|
|
|
|
bouncer.AdministratorAccess(httperror.LoggerHandler(h.endpointDelete))).Methods(http.MethodDelete)
|
|
|
|
h.Handle("/endpoints/{id}/extensions",
|
|
|
|
bouncer.AuthenticatedAccess(httperror.LoggerHandler(h.endpointExtensionAdd))).Methods(http.MethodPost)
|
|
|
|
h.Handle("/endpoints/{id}/extensions/{extensionType}",
|
|
|
|
bouncer.AuthenticatedAccess(httperror.LoggerHandler(h.endpointExtensionRemove))).Methods(http.MethodDelete)
|
2018-10-22 21:03:30 +00:00
|
|
|
h.Handle("/endpoints/{id}/job",
|
|
|
|
bouncer.AdministratorAccess(httperror.LoggerHandler(h.endpointJob))).Methods(http.MethodPost)
|
2018-11-13 03:02:49 +00:00
|
|
|
h.Handle("/endpoints/{id}/snapshot",
|
|
|
|
bouncer.AdministratorAccess(httperror.LoggerHandler(h.endpointSnapshot))).Methods(http.MethodPost)
|
2018-06-11 13:13:19 +00:00
|
|
|
return h
|
|
|
|
}
|