Documentation
¶
Index ¶
- Constants
- Variables
- func IsJwtError(err error) bool
- func NewTokenPayload(token []byte) (*tokens.WebsocketPayload, error)
- type Event
- 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) IsThrottled(e Event) bool
- func (h *Handler) Logger() *log.Entry
- func (h *Handler) OnAuthenticated(fn func() error)
- func (h *Handler) SendClose(code int, reason string) error
- func (h *Handler) SendErrorJson(msg Message, err error, shouldLog ...bool) error
- func (h *Handler) SendJson(v Message) error
- func (h *Handler) SendThrottled(scope string) error
- func (h *Handler) TokenValid() error
- func (h *Handler) User() string
- func (h *Handler) Uuid() uuid.UUID
- type LimiterBucket
- type Message
Constants ¶
const ( FileCollabSubscribeEvent = Event(collab.EventSubscribe) FileCollabUnsubscribeEvent = Event(collab.EventUnsubscribe) FileCollabUpdateEvent = Event(collab.EventUpdateIn) FileCollabAwarenessEvent = Event(collab.EventAwarenessIn) FileCollabSaveEvent = Event(collab.EventSave) FileCollabReloadEvent = Event(collab.EventReload) FileCollabSyncEvent = Event(collab.EventSync) FileCollabParticipantsEvent = Event(collab.EventParticipants) FileCollabSavedEvent = Event(collab.EventSaved) FileCollabConflictEvent = Event(collab.EventConflict) FileCollabErrorEvent = Event(collab.EventError) PermissionFileReadContent = collab.PermissionReadContent PermissionFileUpdate = collab.PermissionUpdate )
const ( AuthenticationSuccessEvent = "auth success" TokenExpiringEvent = "token expiring" TokenExpiredEvent = "token expired" AuthenticationEvent = "auth" SetStateEvent = "set state" SendServerLogsEvent = "send logs" SendCommandEvent = "send command" SuggestCommandEvent = "suggest command" CommandSuggestionsEvent = "command suggestions" SendStatsEvent = "send stats" ErrorEvent = "daemon error" JwtErrorEvent = "jwt error" ThrottledEvent = Event("throttled") )
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" PermissionFileArchive = "file.archive" )
const ErrMissingPermissionMessage = "missing permission"
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) IsThrottled ¶ added in v1.2.0
func (*Handler) OnAuthenticated ¶ added in v1.4.3
OnAuthenticated sets a function that is called when the socket authenticates for the first time. If it returns an error the authentication fails.
func (*Handler) SendClose ¶ added in v1.4.3
SendClose sends a close message with the given code and reason.
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) SendThrottled ¶ added in v1.4.3
SendThrottled tells the client that messages are being dropped because too many were sent.
func (*Handler) TokenValid ¶
TokenValid checks if the JWT is still valid.
type LimiterBucket ¶ added in v1.2.0
type LimiterBucket struct {
// contains filtered or unexported fields
}
func NewLimiter ¶ added in v1.2.0
func NewLimiter() *LimiterBucket