2018-06-11 15:13:19 +02:00
|
|
|
package endpointproxy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gorilla/mux"
|
2018-09-10 12:01:38 +02:00
|
|
|
httperror "github.com/portainer/libhttp/error"
|
2019-03-21 14:20:14 +13:00
|
|
|
"github.com/portainer/portainer/api"
|
|
|
|
"github.com/portainer/portainer/api/http/proxy"
|
|
|
|
"github.com/portainer/portainer/api/http/security"
|
2018-06-11 15:13:19 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// Handler is the HTTP handler used to proxy requests to external APIs.
|
|
|
|
type Handler struct {
|
|
|
|
*mux.Router
|
2018-06-18 11:56:31 +02:00
|
|
|
requestBouncer *security.RequestBouncer
|
|
|
|
EndpointService portainer.EndpointService
|
|
|
|
ProxyManager *proxy.Manager
|
2018-06-11 15:13:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewHandler creates a handler to proxy requests to external APIs.
|
|
|
|
func NewHandler(bouncer *security.RequestBouncer) *Handler {
|
|
|
|
h := &Handler{
|
2018-06-18 11:56:31 +02:00
|
|
|
Router: mux.NewRouter(),
|
|
|
|
requestBouncer: bouncer,
|
2018-06-11 15:13:19 +02:00
|
|
|
}
|
|
|
|
h.PathPrefix("/{id}/azure").Handler(
|
2019-05-24 18:04:58 +12:00
|
|
|
bouncer.RestrictedAccess(httperror.LoggerHandler(h.proxyRequestsToAzureAPI)))
|
2018-06-11 15:13:19 +02:00
|
|
|
h.PathPrefix("/{id}/docker").Handler(
|
2019-05-24 18:04:58 +12:00
|
|
|
bouncer.RestrictedAccess(httperror.LoggerHandler(h.proxyRequestsToDockerAPI)))
|
2018-06-11 15:13:19 +02:00
|
|
|
h.PathPrefix("/{id}/extensions/storidge").Handler(
|
2019-05-24 18:04:58 +12:00
|
|
|
bouncer.RestrictedAccess(httperror.LoggerHandler(h.proxyRequestsToStoridgeAPI)))
|
2018-06-11 15:13:19 +02:00
|
|
|
return h
|
|
|
|
}
|