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) 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 LimiterBucket
- type Message
Constants ¶
View Source
const ( AuthenticationSuccessEvent = Event("auth success") TokenExpiringEvent = Event("token expiring") TokenExpiredEvent = Event("token expired") AuthenticationEvent = Event("auth") SetStateEvent = Event("set state") SendServerLogsEvent = Event("send logs") SendCommandEvent = Event("send command") SendStatsEvent = Event("send stats") ErrorEvent = Event("daemon error") JwtErrorEvent = Event("jwt error") ThrottledEvent = Event("throttled") )
View Source
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 將一個 JWT 解析為 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 使用提供的 context 回傳一個新的 websocket 處理器。
func (*Handler) GetErrorMessage ¶
GetErrorMessage 將錯誤訊息轉換成更易讀的表示方式,並回傳 一個可以用來交叉比對找出觸發特定錯誤的 UUID。
func (*Handler) GetJwt ¶
func (h *Handler) GetJwt() *tokens.WebsocketPayload
GetJwt 以競態安全(race-safe)的方式回傳此 websocket 的 JWT。
func (*Handler) HandleInbound ¶
HandleInbound 處理傳入的 socket 請求,並將其路由到正確的動作。
func (*Handler) IsThrottled ¶
func (*Handler) SendErrorJson ¶
SendErrorJson 透過檢查 token 的權限,將錯誤回傳給已連線的 websocket 實例。如果使用者具有「接收錯誤(receive-errors)」 的授權,我們會回傳實際的錯誤訊息,否則就只回傳一則 標準的錯誤訊息。
type LimiterBucket ¶
type LimiterBucket struct {
// contains filtered or unexported fields
}
func NewLimiter ¶
func NewLimiter() *LimiterBucket
Click to show internal directories.
Click to hide internal directories.