2018-06-11 13:13:19 +00:00
|
|
|
package websocket
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
"github.com/gorilla/websocket"
|
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
|
|
|
)
|
|
|
|
|
|
|
|
// Handler is the HTTP handler used to handle websocket operations.
|
|
|
|
type Handler struct {
|
|
|
|
*mux.Router
|
2019-07-25 22:38:07 +00:00
|
|
|
EndpointService portainer.EndpointService
|
|
|
|
SignatureService portainer.DigitalSignatureService
|
|
|
|
ReverseTunnelService portainer.ReverseTunnelService
|
|
|
|
requestBouncer *security.RequestBouncer
|
|
|
|
connectionUpgrader websocket.Upgrader
|
2018-06-11 13:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewHandler creates a handler to manage websocket operations.
|
2018-06-18 09:56:31 +00:00
|
|
|
func NewHandler(bouncer *security.RequestBouncer) *Handler {
|
2018-06-11 13:13:19 +00:00
|
|
|
h := &Handler{
|
|
|
|
Router: mux.NewRouter(),
|
|
|
|
connectionUpgrader: websocket.Upgrader{},
|
2018-06-18 09:56:31 +00:00
|
|
|
requestBouncer: bouncer,
|
2018-06-11 13:13:19 +00:00
|
|
|
}
|
2018-06-18 09:56:31 +00:00
|
|
|
h.PathPrefix("/websocket/exec").Handler(
|
2019-05-24 06:04:58 +00:00
|
|
|
bouncer.RestrictedAccess(httperror.LoggerHandler(h.websocketExec)))
|
2019-05-09 02:04:40 +00:00
|
|
|
h.PathPrefix("/websocket/attach").Handler(
|
2019-05-24 06:04:58 +00:00
|
|
|
bouncer.RestrictedAccess(httperror.LoggerHandler(h.websocketAttach)))
|
2018-06-11 13:13:19 +00:00
|
|
|
return h
|
|
|
|
}
|