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"
|
2020-07-05 23:21:03 +00:00
|
|
|
portainer "github.com/portainer/portainer/api"
|
2019-03-21 01:20:14 +00:00
|
|
|
"github.com/portainer/portainer/api/http/proxy"
|
|
|
|
"github.com/portainer/portainer/api/http/security"
|
2021-06-16 08:15:29 +00:00
|
|
|
"github.com/portainer/portainer/api/internal/authorization"
|
2021-07-14 09:15:21 +00:00
|
|
|
"github.com/portainer/portainer/api/kubernetes/cli"
|
2018-06-11 13:13:19 +00:00
|
|
|
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
)
|
|
|
|
|
|
|
|
func hideFields(endpoint *portainer.Endpoint) {
|
2020-06-09 02:43:32 +00:00
|
|
|
endpoint.AzureCredentials = portainer.AzureCredentials{}
|
2019-07-20 23:28:11 +00:00
|
|
|
if len(endpoint.Snapshots) > 0 {
|
2020-07-05 23:21:03 +00:00
|
|
|
endpoint.Snapshots[0].SnapshotRaw = portainer.DockerSnapshotRaw{}
|
2019-07-20 23:28:11 +00:00
|
|
|
}
|
2018-06-11 13:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Handler is the HTTP handler used to handle endpoint operations.
|
|
|
|
type Handler struct {
|
|
|
|
*mux.Router
|
2020-05-20 05:23:15 +00:00
|
|
|
requestBouncer *security.RequestBouncer
|
|
|
|
DataStore portainer.DataStore
|
|
|
|
FileService portainer.FileService
|
|
|
|
ProxyManager *proxy.Manager
|
|
|
|
ReverseTunnelService portainer.ReverseTunnelService
|
2020-07-05 23:21:03 +00:00
|
|
|
SnapshotService portainer.SnapshotService
|
2021-07-14 09:15:21 +00:00
|
|
|
K8sClientFactory *cli.ClientFactory
|
2021-01-25 19:16:53 +00:00
|
|
|
ComposeStackManager portainer.ComposeStackManager
|
2021-06-16 08:15:29 +00:00
|
|
|
AuthorizationService *authorization.Service
|
2021-08-17 20:25:34 +00:00
|
|
|
BindAddress string
|
|
|
|
BindAddressHTTPS string
|
2018-06-11 13:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewHandler creates a handler to manage endpoint operations.
|
2020-05-18 08:29:37 +00:00
|
|
|
func NewHandler(bouncer *security.RequestBouncer) *Handler {
|
2018-06-11 13:13:19 +00:00
|
|
|
h := &Handler{
|
2020-05-20 05:23:15 +00:00
|
|
|
Router: mux.NewRouter(),
|
|
|
|
requestBouncer: bouncer,
|
2018-06-11 13:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
h.Handle("/endpoints",
|
2019-10-07 03:10:51 +00:00
|
|
|
bouncer.AdminAccess(httperror.LoggerHandler(h.endpointCreate))).Methods(http.MethodPost)
|
2021-02-09 08:09:06 +00:00
|
|
|
h.Handle("/endpoints/{id}/settings",
|
|
|
|
bouncer.AdminAccess(httperror.LoggerHandler(h.endpointSettingsUpdate))).Methods(http.MethodPut)
|
2021-08-02 06:08:40 +00:00
|
|
|
h.Handle("/endpoints/{id}/association",
|
|
|
|
bouncer.AdminAccess(httperror.LoggerHandler(h.endpointAssociationDelete))).Methods(http.MethodDelete)
|
2018-07-25 19:52:17 +00:00
|
|
|
h.Handle("/endpoints/snapshot",
|
2019-10-07 03:10:51 +00:00
|
|
|
bouncer.AdminAccess(httperror.LoggerHandler(h.endpointSnapshots))).Methods(http.MethodPost)
|
2018-06-11 13:13:19 +00:00
|
|
|
h.Handle("/endpoints",
|
2019-10-07 03:10:51 +00:00
|
|
|
bouncer.RestrictedAccess(httperror.LoggerHandler(h.endpointList))).Methods(http.MethodGet)
|
2018-06-11 13:13:19 +00:00
|
|
|
h.Handle("/endpoints/{id}",
|
2019-10-07 03:10:51 +00:00
|
|
|
bouncer.RestrictedAccess(httperror.LoggerHandler(h.endpointInspect))).Methods(http.MethodGet)
|
2018-06-11 13:13:19 +00:00
|
|
|
h.Handle("/endpoints/{id}",
|
2019-10-07 03:10:51 +00:00
|
|
|
bouncer.AdminAccess(httperror.LoggerHandler(h.endpointUpdate))).Methods(http.MethodPut)
|
2018-06-11 13:13:19 +00:00
|
|
|
h.Handle("/endpoints/{id}",
|
2019-10-07 03:10:51 +00:00
|
|
|
bouncer.AdminAccess(httperror.LoggerHandler(h.endpointDelete))).Methods(http.MethodDelete)
|
2021-07-14 09:15:21 +00:00
|
|
|
h.Handle("/endpoints/{id}/dockerhub/{registryId}",
|
2021-03-24 18:27:32 +00:00
|
|
|
bouncer.RestrictedAccess(httperror.LoggerHandler(h.endpointDockerhubStatus))).Methods(http.MethodGet)
|
2018-06-11 13:13:19 +00:00
|
|
|
h.Handle("/endpoints/{id}/extensions",
|
2019-10-07 03:10:51 +00:00
|
|
|
bouncer.RestrictedAccess(httperror.LoggerHandler(h.endpointExtensionAdd))).Methods(http.MethodPost)
|
2018-06-11 13:13:19 +00:00
|
|
|
h.Handle("/endpoints/{id}/extensions/{extensionType}",
|
2019-10-07 03:10:51 +00:00
|
|
|
bouncer.RestrictedAccess(httperror.LoggerHandler(h.endpointExtensionRemove))).Methods(http.MethodDelete)
|
2018-11-13 03:02:49 +00:00
|
|
|
h.Handle("/endpoints/{id}/snapshot",
|
2019-10-07 03:10:51 +00:00
|
|
|
bouncer.AdminAccess(httperror.LoggerHandler(h.endpointSnapshot))).Methods(http.MethodPost)
|
2019-07-25 22:38:07 +00:00
|
|
|
h.Handle("/endpoints/{id}/status",
|
|
|
|
bouncer.PublicAccess(httperror.LoggerHandler(h.endpointStatusInspect))).Methods(http.MethodGet)
|
2021-07-14 09:15:21 +00:00
|
|
|
h.Handle("/endpoints/{id}/registries",
|
|
|
|
bouncer.AuthenticatedAccess(httperror.LoggerHandler(h.endpointRegistriesList))).Methods(http.MethodGet)
|
|
|
|
h.Handle("/endpoints/{id}/registries/{registryId}",
|
|
|
|
bouncer.AuthenticatedAccess(httperror.LoggerHandler(h.endpointRegistryInspect))).Methods(http.MethodGet)
|
|
|
|
h.Handle("/endpoints/{id}/registries/{registryId}",
|
|
|
|
bouncer.AuthenticatedAccess(httperror.LoggerHandler(h.endpointRegistryAccess))).Methods(http.MethodPut)
|
2018-06-11 13:13:19 +00:00
|
|
|
return h
|
|
|
|
}
|