terminal

package
v0.0.0-...-8149b9c Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	END_OF_TRANSMISSION = "\u0004"
)

Variables

View Source
var TerminalSessions = SessionMap{Sessions: make(map[string]TerminalSession)}

TerminalSessions is a global variable that is used to manage all terminal sessions.

Functions

func GenTerminalSessionId

func GenTerminalSessionId() (string, error)

GenTerminalSessionId generates a random session ID string. This ID is used to identify the session when the client opens the WebSocket connection.

func HandleTerminalSession

func HandleTerminalSession(session *websocket.Conn)

HandleTerminalSession is called for binding any new connections.

func WaitForTerminal

func WaitForTerminal(k8sClient kubernetes.Interface, cfg *rest.Config, clusterName, namespaceName, podName, containerName, shell, sessionId string, logger *zap.Logger)

WaitForTerminal is called from capp controller as a goroutine. Waits for the WebSocket connection to be opened by the client the session to be Bound in handleTerminalSession. After the session is bound, it manages the session by opening the stream and closing it in case of an error or timeout.

Types

type PtyHandler

type PtyHandler interface {
	io.Reader
	io.Writer
	remotecommand.TerminalSizeQueue
}

PtyHandler is what remotecommand expects from a pty.

type SessionMap

type SessionMap struct {
	Sessions map[string]TerminalSession
	Lock     sync.RWMutex
}

SessionMap stores a map of all TerminalSession objects and a lock to avoid concurrent conflict.

func (*SessionMap) Close

func (sm *SessionMap) Close(sessionId string)

Close shuts down the WebSocket connection. Can happen if the process exits or if there is an error starting up the process

func (*SessionMap) Get

func (sm *SessionMap) Get(sessionId string) TerminalSession

Get returns a given terminalSession by sessionId.

func (*SessionMap) Set

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

Set stores a TerminalSession to the SessionMap.

type TerminalMessage

type TerminalMessage struct {
	Op, Data, SessionID string
	Rows, Cols          uint16
}

TerminalMessage is the messaging protocol between the Client and the TerminalSession.

OP DIRECTION FIELD(S) USED DESCRIPTION --------------------------------------------------------------------- bind fe->be SessionID Id sent back from TerminalResponse stdin fe->be Data Keystrokes/paste buffer resize fe->be Rows, Cols New terminal_utils size stdout be->fe Data Output from the process toast be->fe Data OOB message to be shown to the user

type TerminalSession

type TerminalSession struct {
	Id        string
	Bound     chan error
	WebSocket *websocket.Conn
	SizeChan  chan remotecommand.TerminalSize
}

TerminalSession implements PtyHandler (using a WebSocket connection) This is the object that is used to communicate with container terminal.

func (TerminalSession) Next

Next handles pty->process resize events Called in a loop from remotecommand as long as the process is running

func (TerminalSession) Read

func (t TerminalSession) Read(p []byte) (int, error)

Read handles pty->process messages (stdin, resize) Called in a loop from remotecommand as long as the process is running

func (TerminalSession) Toast

func (t TerminalSession) Toast(p string) error

Toast can be used to send the user any OOB messages. (OOB -messages are non-standard messages or notifications sent outside the main communication channel.) hterm puts these in the center of the terminal_utils

func (TerminalSession) Write

func (t TerminalSession) Write(p []byte) (int, error)

Write handles process->pty stdout Called from remotecommand whenever there is any output

Jump to

Keyboard shortcuts

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