2018-06-11 13:13:19 +00:00
|
|
|
package endpointproxy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"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/proxy"
|
|
|
|
"github.com/portainer/portainer/api/http/security"
|
2018-06-11 13:13:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Handler is the HTTP handler used to proxy requests to external APIs.
|
|
|
|
type Handler struct {
|
|
|
|
*mux.Router
|
2019-07-25 22:38:07 +00:00
|
|
|
requestBouncer *security.RequestBouncer
|
|
|
|
EndpointService portainer.EndpointService
|
|
|
|
SettingsService portainer.SettingsService
|
|
|
|
ProxyManager *proxy.Manager
|
|
|
|
ReverseTunnelService portainer.ReverseTunnelService
|
2018-06-11 13:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewHandler creates a handler to proxy requests to external APIs.
|
|
|
|
func NewHandler(bouncer *security.RequestBouncer) *Handler {
|
|
|
|
h := &Handler{
|
2018-06-18 09:56:31 +00:00
|
|
|
Router: mux.NewRouter(),
|
|
|
|
requestBouncer: bouncer,
|
2018-06-11 13:13:19 +00:00
|
|
|
}
|
|
|
|
h.PathPrefix("/{id}/docker").Handler(
|
2019-10-07 03:10:51 +00:00
|
|
|
bouncer.AuthenticatedAccess(httperror.LoggerHandler(h.proxyRequestsToDockerAPI)))
|
2019-05-26 22:41:12 +00:00
|
|
|
h.PathPrefix("/{id}/storidge").Handler(
|
2019-10-07 03:10:51 +00:00
|
|
|
bouncer.AuthenticatedAccess(httperror.LoggerHandler(h.proxyRequestsToStoridgeAPI)))
|
2018-06-11 13:13:19 +00:00
|
|
|
return h
|
|
|
|
}
|