2018-06-11 13:13:19 +00:00
|
|
|
package endpointgroups
|
|
|
|
|
|
|
|
import (
|
2021-06-16 08:15:29 +00:00
|
|
|
"github.com/portainer/portainer/api/internal/authorization"
|
2018-06-11 13:13:19 +00:00
|
|
|
"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
|
|
|
"github.com/portainer/portainer/api"
|
|
|
|
"github.com/portainer/portainer/api/http/security"
|
2018-06-11 13:13:19 +00:00
|
|
|
)
|
|
|
|
|
2021-09-20 00:14:22 +00:00
|
|
|
// Handler is the HTTP handler used to handle environment(endpoint) group operations.
|
2018-06-11 13:13:19 +00:00
|
|
|
type Handler struct {
|
|
|
|
*mux.Router
|
2021-06-16 08:15:29 +00:00
|
|
|
AuthorizationService *authorization.Service
|
2020-08-11 05:41:37 +00:00
|
|
|
DataStore portainer.DataStore
|
2018-06-11 13:13:19 +00:00
|
|
|
}
|
|
|
|
|
2021-09-20 00:14:22 +00:00
|
|
|
// NewHandler creates a handler to manage environment(endpoint) group operations.
|
2018-06-11 13:13:19 +00:00
|
|
|
func NewHandler(bouncer *security.RequestBouncer) *Handler {
|
|
|
|
h := &Handler{
|
|
|
|
Router: mux.NewRouter(),
|
|
|
|
}
|
|
|
|
h.Handle("/endpoint_groups",
|
2019-10-07 03:10:51 +00:00
|
|
|
bouncer.AdminAccess(httperror.LoggerHandler(h.endpointGroupCreate))).Methods(http.MethodPost)
|
2018-06-11 13:13:19 +00:00
|
|
|
h.Handle("/endpoint_groups",
|
2019-10-07 03:10:51 +00:00
|
|
|
bouncer.RestrictedAccess(httperror.LoggerHandler(h.endpointGroupList))).Methods(http.MethodGet)
|
2018-06-11 13:13:19 +00:00
|
|
|
h.Handle("/endpoint_groups/{id}",
|
2019-10-07 03:10:51 +00:00
|
|
|
bouncer.AdminAccess(httperror.LoggerHandler(h.endpointGroupInspect))).Methods(http.MethodGet)
|
2018-06-11 13:13:19 +00:00
|
|
|
h.Handle("/endpoint_groups/{id}",
|
2019-10-07 03:10:51 +00:00
|
|
|
bouncer.AdminAccess(httperror.LoggerHandler(h.endpointGroupUpdate))).Methods(http.MethodPut)
|
2018-06-11 13:13:19 +00:00
|
|
|
h.Handle("/endpoint_groups/{id}",
|
2019-10-07 03:10:51 +00:00
|
|
|
bouncer.AdminAccess(httperror.LoggerHandler(h.endpointGroupDelete))).Methods(http.MethodDelete)
|
2019-07-20 23:28:11 +00:00
|
|
|
h.Handle("/endpoint_groups/{id}/endpoints/{endpointId}",
|
2019-10-07 03:10:51 +00:00
|
|
|
bouncer.AdminAccess(httperror.LoggerHandler(h.endpointGroupAddEndpoint))).Methods(http.MethodPut)
|
2019-07-20 23:28:11 +00:00
|
|
|
h.Handle("/endpoint_groups/{id}/endpoints/{endpointId}",
|
2019-10-07 03:10:51 +00:00
|
|
|
bouncer.AdminAccess(httperror.LoggerHandler(h.endpointGroupDeleteEndpoint))).Methods(http.MethodDelete)
|
2018-06-11 13:13:19 +00:00
|
|
|
return h
|
|
|
|
}
|