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(m Message) error
- func (h *Handler) ListenForExpiration(ctx context.Context)
- func (h *Handler) ListenForServerEvents(ctx context.Context)
- 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" PermissionReceiveBackups = "backup.read" )
Variables ¶
Functions ¶
func IsJwtError ¶
func NewTokenPayload ¶
func NewTokenPayload(token []byte) (*tokens.WebsocketPayload, error)
Parses a JWT into a websocket token payload.
Types ¶
type Handler ¶
type Handler struct { sync.RWMutex Connection *websocket.Conn // contains filtered or unexported fields }
func GetHandler ¶
Returns a new websocket handler using the context provided.
func (*Handler) 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
func (*Handler) HandleInbound ¶
Handle the inbound socket request and route it to the proper server action.
func (*Handler) ListenForExpiration ¶
Checks the time to expiration on the JWT every 30 seconds until the token has expired. If we are within 3 minutes of the token expiring, send a notice over the socket that it is expiring soon. If it has expired, send that notice as well.
func (*Handler) ListenForServerEvents ¶
Listens for different events happening on a server and sends them along to the connected websocket.
func (*Handler) 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.