2022-08-11 04:33:29 +00:00
|
|
|
package containers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
httperror "github.com/portainer/libhttp/error"
|
2023-05-29 21:36:10 +00:00
|
|
|
"github.com/portainer/portainer/api/dataservices"
|
2022-08-11 04:33:29 +00:00
|
|
|
"github.com/portainer/portainer/api/docker"
|
2023-05-29 21:36:10 +00:00
|
|
|
dockerclient "github.com/portainer/portainer/api/docker/client"
|
2022-08-11 04:33:29 +00:00
|
|
|
"github.com/portainer/portainer/api/http/security"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Handler struct {
|
|
|
|
*mux.Router
|
2023-05-29 21:36:10 +00:00
|
|
|
dockerClientFactory *dockerclient.ClientFactory
|
|
|
|
dataStore dataservices.DataStore
|
|
|
|
containerService *docker.ContainerService
|
2023-06-16 13:44:22 +00:00
|
|
|
bouncer security.BouncerService
|
2022-08-11 04:33:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewHandler creates a handler to process non-proxied requests to docker APIs directly.
|
2023-06-16 13:44:22 +00:00
|
|
|
func NewHandler(routePrefix string, bouncer security.BouncerService, dataStore dataservices.DataStore, dockerClientFactory *dockerclient.ClientFactory, containerService *docker.ContainerService) *Handler {
|
2022-08-11 04:33:29 +00:00
|
|
|
h := &Handler{
|
2023-05-29 21:36:10 +00:00
|
|
|
Router: mux.NewRouter(),
|
|
|
|
dataStore: dataStore,
|
2022-08-11 04:33:29 +00:00
|
|
|
dockerClientFactory: dockerClientFactory,
|
2023-05-29 21:36:10 +00:00
|
|
|
containerService: containerService,
|
|
|
|
bouncer: bouncer,
|
2022-08-11 04:33:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
router := h.PathPrefix(routePrefix).Subrouter()
|
|
|
|
router.Use(bouncer.AuthenticatedAccess)
|
|
|
|
|
|
|
|
router.Handle("/{containerId}/gpus", httperror.LoggerHandler(h.containerGpusInspect)).Methods(http.MethodGet)
|
2023-05-29 21:36:10 +00:00
|
|
|
router.Handle("/{containerId}/recreate", httperror.LoggerHandler(h.recreate)).Methods(http.MethodPost)
|
2022-08-11 04:33:29 +00:00
|
|
|
|
|
|
|
return h
|
|
|
|
}
|