socket

package
v0.0.86 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2023 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OpStdout = "stdout"
	OpStdin  = "stdin"
	OpResize = "resize"
	OpToast  = "toast"
)

Variables

View Source
var (
	ETX                 = []byte("\u0003")
	END_OF_TRANSMISSION = []byte("\u0004")
)

Functions

func GenMyPtyHandlerId

func GenMyPtyHandlerId() (string, error)

GenMyPtyHandlerId generates a random session ID string. The format is not really interesting. This ID is used to identify the session when the client opens the SockJS connection. Not the same as the SockJS session id! We can't use that as that is generated on the client side and we don't have it yet at this point.

func HandleExecShell

func HandleExecShell(input *websocket_pb.WsHandleExecShellInput, conn *WsConn) (string, error)

func HandleWsAuthorize

func HandleWsAuthorize(c *WsConn, t websocket_pb.Type, message []byte)

func HandleWsHandleCloseShell

func HandleWsHandleCloseShell(c *WsConn, t websocket_pb.Type, message []byte)

func HandleWsHandleExecShell

func HandleWsHandleExecShell(c *WsConn, t websocket_pb.Type, message []byte)

func HandleWsHandleExecShellMsg

func HandleWsHandleExecShellMsg(c *WsConn, t websocket_pb.Type, message []byte)

func HandleWsHandleSetLang added in v0.0.28

func HandleWsHandleSetLang(c *WsConn, t websocket_pb.Type, message []byte)

func WaitForTerminal

func WaitForTerminal(conn *WsConn, k8sClient kubernetes.Interface, cfg *rest.Config, container *Container, shell, sessionId string)

WaitForTerminal is called from apihandler.handleAttach as a goroutine Waits for the SockJS connection to be opened by the client the session to be bound in handleMyPtyHandler

Types

type Container

type Container struct {
	Namespace string `json:"namespace"`
	Pod       string `json:"pod"`
	Container string `json:"container"`
	ClusterID int64  `json:"cluster_id"`
	Cluster   *models.Cluster
}

type HandleRequestFunc

type HandleRequestFunc func(c *WsConn, t websocket_pb.Type, message []byte)

type Msger

type Msger interface {
	SendEndError(error)
	SendError(error)
	SendMsg(string)
	SendProtoMsg(plugins.WebsocketMessage)
}

func NewMessageSender

func NewMessageSender(conn *WsConn, slugName string, wsType websocket_pb.Type) Msger

type MyPtyHandler

type MyPtyHandler struct {
	Container
	// contains filtered or unexported fields
}

func (*MyPtyHandler) Close

func (t *MyPtyHandler) Close(reason string) bool

func (*MyPtyHandler) CloseDoneChan added in v0.0.47

func (t *MyPtyHandler) CloseDoneChan() bool

func (*MyPtyHandler) Cols added in v0.0.46

func (t *MyPtyHandler) Cols() uint16

func (*MyPtyHandler) IsClosed added in v0.0.46

func (t *MyPtyHandler) IsClosed() bool

func (*MyPtyHandler) Next

func (*MyPtyHandler) Read

func (t *MyPtyHandler) Read(p []byte) (n int, err error)

func (*MyPtyHandler) Recorder added in v0.0.46

func (t *MyPtyHandler) Recorder() *Recorder

func (*MyPtyHandler) ResetTerminalRowCol added in v0.0.46

func (t *MyPtyHandler) ResetTerminalRowCol(reset bool)

func (*MyPtyHandler) Resize added in v0.0.47

func (t *MyPtyHandler) Resize(size remotecommand.TerminalSize)

func (*MyPtyHandler) Rows added in v0.0.46

func (t *MyPtyHandler) Rows() uint16

func (*MyPtyHandler) Send added in v0.0.47

func (*MyPtyHandler) TerminalMessageChan added in v0.0.46

func (t *MyPtyHandler) TerminalMessageChan() chan *websocket_pb.TerminalMessage

func (*MyPtyHandler) Toast

func (t *MyPtyHandler) Toast(p string) error

Toast can be used to send the user any OOB messages hterm puts these in the center of the terminal

func (*MyPtyHandler) Write

func (t *MyPtyHandler) Write(p []byte) (n int, err error)

type PtyHandler

type PtyHandler interface {
	Recorder() *Recorder
	Toast(string) error

	Send(*websocket_pb.TerminalMessage)
	Resize(remotecommand.TerminalSize)

	ResetTerminalRowCol(bool)
	TerminalMessageChan() chan *websocket_pb.TerminalMessage
	Rows() uint16
	Cols() uint16

	Close(string) bool
	IsClosed() bool

	io.Reader
	io.Writer
	remotecommand.TerminalSizeQueue
}

PtyHandler is what remotecommand expects from a pty

type Recorder added in v0.0.22

type Recorder struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*Recorder) Close added in v0.0.22

func (r *Recorder) Close() error

func (*Recorder) HeadLine added in v0.0.54

func (r *Recorder) HeadLine(cols, rows uint16)

func (*Recorder) Resize added in v0.0.46

func (r *Recorder) Resize(cols, rows uint16)

func (*Recorder) Write added in v0.0.22

func (r *Recorder) Write(data string) (err error)

type SessionMap

type SessionMap struct {
	Sessions map[string]PtyHandler
	// contains filtered or unexported fields
}

SessionMap stores a map of all MyPtyHandler objects and a sessLock to avoid concurrent conflict

func (*SessionMap) Close

func (sm *SessionMap) Close(sessionId string, status uint32, reason string)

Close shuts down the SockJS connection and sends the status code and reason to the client Can happen if the process exits or if there is an error starting up the process For now the status code is unused and reason is shown to the user (unless "")

func (*SessionMap) CloseAll

func (sm *SessionMap) CloseAll()

func (*SessionMap) Get

func (sm *SessionMap) Get(sessionId string) (PtyHandler, bool)

Get return a given terminalSession by sessionId

func (*SessionMap) Send

func (*SessionMap) Set

func (sm *SessionMap) Set(sessionId string, session PtyHandler)

Set store a MyPtyHandler to SessionMap

type SessionMapper

type SessionMapper interface {
	Send(message *websocket_pb.TerminalMessage)
	Get(sessionId string) (PtyHandler, bool)
	Set(sessionId string, session PtyHandler)
	CloseAll()
	Close(sessionId string, status uint32, reason string)
}

type TerminalResponse

type TerminalResponse struct {
	ID string `json:"id"`
}

type WaitSocketExit

type WaitSocketExit struct {
	// contains filtered or unexported fields
}

func NewWaitSocketExit

func NewWaitSocketExit() *WaitSocketExit

func (*WaitSocketExit) Count

func (w *WaitSocketExit) Count() int

func (*WaitSocketExit) Dec

func (w *WaitSocketExit) Dec()

func (*WaitSocketExit) Inc

func (w *WaitSocketExit) Inc()

func (*WaitSocketExit) Wait

func (w *WaitSocketExit) Wait()

type WebsocketManager

type WebsocketManager struct{}

func NewWebsocketManager

func NewWebsocketManager() *WebsocketManager

func (*WebsocketManager) Info

func (wc *WebsocketManager) Info(writer http.ResponseWriter, request *http.Request)

func (*WebsocketManager) Ws

type WsConn

type WsConn struct {
	// contains filtered or unexported fields
}

func (*WsConn) GetShellChannel

func (c *WsConn) GetShellChannel(sessionID string) (chan *websocket_pb.TerminalMessage, error)

func (*WsConn) GetUser

func (c *WsConn) GetUser() *contracts.UserInfo

func (*WsConn) SetUser

func (c *WsConn) SetUser(info *contracts.UserInfo)

func (*WsConn) Shutdown

func (c *WsConn) Shutdown()

type WsResponse

type WsResponse = websocket_pb.WsMetadataResponse

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL