Documentation ¶
Index ¶
- Constants
- 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(err error) error
- func (h *Handler) SendJson(v *Message) error
- func (h *Handler) TokenValid() error
- type Message
Constants ¶
const ( AuthenticationSuccessEvent = "auth success" TokenExpiringEvent = "token expiring" TokenExpiredEvent = "token expired" AuthenticationEvent = "auth" SetStateEvent = "set state" SendServerLogsEvent = "send logs" SendCommandEvent = "send command" ErrorEvent = "daemon error" )
const ( PermissionConnect = "websocket.*" PermissionSendCommand = "control.console" PermissionSendPowerStart = "control.start" PermissionSendPowerStop = "control.stop" PermissionSendPowerRestart = "control.restart" PermissionReceiveErrors = "admin.errors" PermissionReceiveInstall = "admin.install" PermissionReceiveBackups = "backup.read" )
Variables ¶
This section is empty.
Functions ¶
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.
type Message ¶
type Message struct { // The event to perform. Should be one of the following that are supported: // // - status : Returns the server's power state. // - logs : Returns the server log data at the time of the request. // - power : Performs a power action aganist the server based the data. // - command : Performs a command on a server using the data field. Event string `json:"event"` // The data to pass along, only used by power/command currently. Other requests // should either omit the field or pass an empty value as it is ignored. Args []string `json:"args,omitempty"` }