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"
|
2018-06-11 13:13:19 +00:00
|
|
|
"github.com/portainer/portainer"
|
2018-06-18 09:56:31 +00:00
|
|
|
"github.com/portainer/portainer/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
|
|
|
|
EndpointService portainer.EndpointService
|
|
|
|
SignatureService portainer.DigitalSignatureService
|
2018-06-18 09:56:31 +00:00
|
|
|
requestBouncer *security.RequestBouncer
|
2018-06-11 13:13:19 +00:00
|
|
|
connectionUpgrader websocket.Upgrader
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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(
|
|
|
|
bouncer.AuthenticatedAccess(httperror.LoggerHandler(h.websocketExec)))
|
2018-06-11 13:13:19 +00:00
|
|
|
return h
|
|
|
|
}
|