2018-06-11 13:13:19 +00:00
|
|
|
package registries
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
2018-12-09 03:49:27 +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/proxy"
|
|
|
|
"github.com/portainer/portainer/api/http/security"
|
2018-06-11 13:13:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func hideFields(registry *portainer.Registry) {
|
|
|
|
registry.Password = ""
|
2018-12-09 03:49:27 +00:00
|
|
|
registry.ManagementConfiguration = nil
|
2018-06-11 13:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Handler is the HTTP handler used to handle registry 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
|
2018-06-11 13:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewHandler creates a handler to manage registry operations.
|
|
|
|
func NewHandler(bouncer *security.RequestBouncer) *Handler {
|
|
|
|
h := &Handler{
|
2019-02-25 00:02:49 +00:00
|
|
|
Router: mux.NewRouter(),
|
|
|
|
requestBouncer: bouncer,
|
2018-06-11 13:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
h.Handle("/registries",
|
2019-10-07 03:10:51 +00:00
|
|
|
bouncer.AdminAccess(httperror.LoggerHandler(h.registryCreate))).Methods(http.MethodPost)
|
2018-06-11 13:13:19 +00:00
|
|
|
h.Handle("/registries",
|
2019-10-07 03:10:51 +00:00
|
|
|
bouncer.RestrictedAccess(httperror.LoggerHandler(h.registryList))).Methods(http.MethodGet)
|
2018-06-11 13:13:19 +00:00
|
|
|
h.Handle("/registries/{id}",
|
2019-10-07 03:10:51 +00:00
|
|
|
bouncer.RestrictedAccess(httperror.LoggerHandler(h.registryInspect))).Methods(http.MethodGet)
|
2018-06-11 13:13:19 +00:00
|
|
|
h.Handle("/registries/{id}",
|
2019-10-07 03:10:51 +00:00
|
|
|
bouncer.AdminAccess(httperror.LoggerHandler(h.registryUpdate))).Methods(http.MethodPut)
|
2018-12-09 03:49:27 +00:00
|
|
|
h.Handle("/registries/{id}/configure",
|
2019-10-07 03:10:51 +00:00
|
|
|
bouncer.AdminAccess(httperror.LoggerHandler(h.registryConfigure))).Methods(http.MethodPost)
|
2018-06-11 13:13:19 +00:00
|
|
|
h.Handle("/registries/{id}",
|
2019-10-07 03:10:51 +00:00
|
|
|
bouncer.AdminAccess(httperror.LoggerHandler(h.registryDelete))).Methods(http.MethodDelete)
|
2019-11-12 03:28:31 +00:00
|
|
|
h.PathPrefix("/registries/proxies/gitlab").Handler(
|
|
|
|
bouncer.AdminAccess(httperror.LoggerHandler(h.proxyRequestsToGitlabAPIWithoutRegistry)))
|
2018-06-11 13:13:19 +00:00
|
|
|
return h
|
|
|
|
}
|