Documentation ¶
Overview ¶
Package websocket starts a WebSocket service forwarding internal events to http clients
Index ¶
- Constants
- func ClearSession(session *melody.Session)
- func Marshal(m Message) []byte
- func NewErrorMessage(e error) []byte
- func NewErrorMessageString(e string) []byte
- type ChatHandler
- type ChatMessage
- type ChatMessageType
- type Message
- type MessageType
- type NodeChangeEventWithInfo
- type NodeEventsBatcher
- type WebsocketHandler
- func (w *WebsocketHandler) BroadcastActivityEvent(ctx context.Context, event *activity.PostActivityEvent) error
- func (w *WebsocketHandler) BroadcastIDMChangeEvent(ctx context.Context, event *idm.ChangeEvent) error
- func (w *WebsocketHandler) BroadcastNodeChangeEvent(ctx context.Context, event *NodeChangeEventWithInfo) error
- func (w *WebsocketHandler) BroadcastTaskChangeEvent(ctx context.Context, event *jobs.TaskChangeEvent) error
- func (w *WebsocketHandler) HandleNodeChangeEvent(ctx context.Context, event *tree.NodeChangeEvent) error
- func (w *WebsocketHandler) InitHandlers(ctx context.Context)
- func (w *WebsocketHandler) MatchPolicies(policies []*service.ResourcePolicy, subjects []string, ...) bool
Constants ¶
const ( SessionRolesKey = "roles" SessionWorkspacesKey = "workspaces" SessionAccessListKey = "accessList" SessionUsernameKey = "user" SessionProfileKey = "profile" SessionClaimsKey = "claims" SessionSubjectsKey = "subjects" SessionLimiterKey = "limiter" SessionMetaContext = "metaContext" )
const LimiterBurst = 20
const LimiterRate = 30
const (
SessionRoomKey = "room"
)
Variables ¶
This section is empty.
Functions ¶
func ClearSession ¶
func NewErrorMessage ¶
func NewErrorMessageString ¶
Types ¶
type ChatHandler ¶
type ChatHandler struct { Websocket *melody.Melody Pool nodes.SourcesPool // contains filtered or unexported fields }
func NewChatHandler ¶
func NewChatHandler(ctx context.Context) *ChatHandler
NewChatHandler creates a new ChatHandler
func (*ChatHandler) BroadcastChatMessage ¶
BroadcastChatMessage sends chat message to connected sessions
type ChatMessage ¶
type ChatMessage struct { Type ChatMessageType `json:"@type"` RoomType chat.RoomType Payload string }
type ChatMessageType ¶
type ChatMessageType string
const ( JoinRoom ChatMessageType = "join" LeaveRoom ChatMessageType = "leave" PostMessage ChatMessageType = "msg" )
type Message ¶
type Message struct { Type MessageType `json:"@type"` JWT string `json:"jwt"` Error string `json:"error"` }
Message passes JWT
type MessageType ¶
type MessageType string
const ( MsgSubscribe MessageType = "subscribe" MsgUnsubscribe MessageType = "unsubscribe" MsgError MessageType = "error" )
type NodeChangeEventWithInfo ¶
type NodeChangeEventWithInfo struct { tree.NodeChangeEvent // contains filtered or unexported fields }
type NodeEventsBatcher ¶
type NodeEventsBatcher struct {
// contains filtered or unexported fields
}
NodeEventsBatcher buffers events with same node.uuid and flatten them into one where possible
func NewEventsBatcher ¶
func NewEventsBatcher(timeout time.Duration, uuid string, out chan *NodeChangeEventWithInfo, done chan string) *NodeEventsBatcher
NewEventsBatcher creates a new NodeEventsBatcher
func (*NodeEventsBatcher) EnqueueWithRecover ¶ added in v4.0.1
func (n *NodeEventsBatcher) EnqueueWithRecover(ev *NodeChangeEventWithInfo) (err error)
func (*NodeEventsBatcher) Flush ¶
func (n *NodeEventsBatcher) Flush()
Flush applies the events buffered as one
type WebsocketHandler ¶
type WebsocketHandler struct { Websocket *melody.Melody EventRouter *compose.Reverse // contains filtered or unexported fields }
func NewWebSocketHandler ¶
func NewWebSocketHandler(serviceCtx context.Context) *WebsocketHandler
func (*WebsocketHandler) BroadcastActivityEvent ¶
func (w *WebsocketHandler) BroadcastActivityEvent(ctx context.Context, event *activity.PostActivityEvent) error
BroadcastActivityEvent listens to activities and broadcast them to sessions with the adequate user.
func (*WebsocketHandler) BroadcastIDMChangeEvent ¶
func (w *WebsocketHandler) BroadcastIDMChangeEvent(ctx context.Context, event *idm.ChangeEvent) error
BroadcastIDMChangeEvent listens to ACL events and broadcast them to sessions if the Role, User, or Workspace is concerned This triggers a registry reload in the UX (and eventually a change of permissions)
func (*WebsocketHandler) BroadcastNodeChangeEvent ¶
func (w *WebsocketHandler) BroadcastNodeChangeEvent(ctx context.Context, event *NodeChangeEventWithInfo) error
BroadcastNodeChangeEvent will browse the currently registered websocket sessions and decide whether to broadcast the event or not.
func (*WebsocketHandler) BroadcastTaskChangeEvent ¶
func (w *WebsocketHandler) BroadcastTaskChangeEvent(ctx context.Context, event *jobs.TaskChangeEvent) error
BroadcastTaskChangeEvent listens to tasks events and broadcast them to sessions with the adequate user.
func (*WebsocketHandler) HandleNodeChangeEvent ¶
func (w *WebsocketHandler) HandleNodeChangeEvent(ctx context.Context, event *tree.NodeChangeEvent) error
HandleNodeChangeEvent listens to NodeChangeEvents and either broadcast them directly, or use NodeEventsBatcher to buffer them and flatten them into one.
func (*WebsocketHandler) InitHandlers ¶
func (w *WebsocketHandler) InitHandlers(ctx context.Context)
func (*WebsocketHandler) MatchPolicies ¶
func (w *WebsocketHandler) MatchPolicies(policies []*service.ResourcePolicy, subjects []string, action service.ResourcePolicyAction) bool
MatchPolicies creates a memory-based policy stack checker to check if action is allowed or denied. It uses a DenyByDefault strategy