Documentation ¶
Index ¶
- Constants
- Variables
- func IsJwtError(err error) bool
- func NewTokenPayload(token []byte) (*tokens.WebsocketPayload, error)
- type Handler
- func (h *Handler) GetErrorMessage(msg string) (string, uuid.UUID)
- func (h *Handler) GetJwt() *tokens.WebsocketPayload
- func (h *Handler) HandleInbound(ctx context.Context, m Message) error
- func (h *Handler) Logger() *log.Entry
- func (h *Handler) SendErrorJson(msg Message, err error, shouldLog ...bool) error
- func (h *Handler) SendJson(v Message) error
- func (h *Handler) TokenValid() error
- func (h *Handler) Uuid() uuid.UUID
- type Message
Constants ¶
const ( AuthenticationSuccessEvent = "auth success" TokenExpiringEvent = "token expiring" TokenExpiredEvent = "token expired" AuthenticationEvent = "auth" SetStateEvent = "set state" SendServerLogsEvent = "send logs" SendCommandEvent = "send command" SendStatsEvent = "send stats" ErrorEvent = "daemon error" JwtErrorEvent = "jwt error" )
const ( PermissionConnect = "websocket.connect" PermissionSendCommand = "control.console" PermissionSendPowerStart = "control.start" PermissionSendPowerStop = "control.stop" PermissionSendPowerRestart = "control.restart" PermissionReceiveErrors = "admin.websocket.errors" PermissionReceiveInstall = "admin.websocket.install" PermissionReceiveTransfer = "admin.websocket.transfer" PermissionReceiveBackups = "backup.read" )
Variables ¶
Functions ¶
func IsJwtError ¶
func NewTokenPayload ¶
func NewTokenPayload(token []byte) (*tokens.WebsocketPayload, error)
NewTokenPayload parses a JWT into a websocket token payload.
Types ¶
type Handler ¶
type Handler struct { sync.RWMutex `json:"-"` Connection *websocket.Conn `json:"-"` // contains filtered or unexported fields }
func GetHandler ¶
func GetHandler(s *server.Server, w http.ResponseWriter, r *http.Request, c *gin.Context) (*Handler, error)
GetHandler returns a new websocket handler using the context provided.
func (*Handler) GetErrorMessage ¶
GetErrorMessage converts an error message into a more readable representation and returns a UUID that can be cross-referenced to find the specific error that triggered.
func (*Handler) GetJwt ¶
func (h *Handler) GetJwt() *tokens.WebsocketPayload
GetJwt returns the JWT for the websocket in a race-safe manner.
func (*Handler) HandleInbound ¶
HandleInbound handles an inbound socket request and route it to the proper action.
func (*Handler) SendErrorJson ¶
SendErrorJson sends an error back to the connected websocket instance by checking the permissions of the token. If the user has the "receive-errors" grant we will send back the actual error message, otherwise we just send back a standard error message.
func (*Handler) TokenValid ¶
TokenValid checks if the JWT is still valid.