terminal

package module
v0.0.0-...-62e9b61 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2023 License: MIT Imports: 18 Imported by: 72

README

Gitlab Terminal

This Go library contains the code that powers the web terminal implementation of Gitlab for environments and CI jobs.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	BrowserPingInterval = 30 * time.Second
)

Functions

func CloseAfterMaxTime

func CloseAfterMaxTime(proxy Proxy, maxSessionTime int)

func NewIOWrapper

func NewIOWrapper(conn Connection) *ioWrapper

func ProxyFileDescriptor

func ProxyFileDescriptor(w http.ResponseWriter, r *http.Request, fd *os.File, proxy *FileDescriptorProxy)

ProxyFileDescriptor takes the given request, upgrades the connection to a WebSocket connection. A bi-directional stream is opened between the WebSocket and FileDescriptor that pipes the STDIN from the WebSocket to the FileDescriptor , and STDERR/STDOUT back to the WebSocket.

func ProxyStream

func ProxyStream(w http.ResponseWriter, r *http.Request, stream io.ReadWriteCloser, proxy *StreamProxy)

ProxyStream takes the given request, upgrades the connection to a WebSocket connection, and also takes a dst ReadWriteCloser where a bi-directional stream is set up, were the STDIN of the WebSocket it sent dst and the STDOUT/STDERR of dst is written to the WebSocket connection. The messages to the WebSocket are encoded into binary text.

func ProxyWebSocket

func ProxyWebSocket(w http.ResponseWriter, r *http.Request, terminal *TerminalSettings, proxy *WebSocketProxy)

ProxyWebSocket takes the given request, upgrades the connection to a WebSocket connection. The terminal settings are used to connect to the dst WebSocket connection where it establishes a bi-directional stream between both web sockets.

Types

type Connection

type Connection interface {
	UnderlyingConn() net.Conn
	ReadMessage() (int, []byte, error)
	WriteMessage(int, []byte) error
	WriteControl(int, []byte, time.Time) error
}

An abstraction of gorilla's *websocket.Conn

func Wrap

func Wrap(conn Connection, subprotocol string) Connection

type FileDescriptorProxy

type FileDescriptorProxy struct {
	StopCh chan error
}

func NewFileDescriptorProxy

func NewFileDescriptorProxy(stoppers int) *FileDescriptorProxy

stoppers is the number of goroutines that may attempt to call Stop()

func (*FileDescriptorProxy) GetStopCh

func (p *FileDescriptorProxy) GetStopCh() chan error

func (*FileDescriptorProxy) Serve

func (p *FileDescriptorProxy) Serve(upstream, downstream io.ReadWriter, upstreamAddr, downstreamAddr string) error

type Proxy

type Proxy interface {
	GetStopCh() chan error
}

type StreamProxy

type StreamProxy struct {
	StopCh chan error
}

func NewStreamProxy

func NewStreamProxy(stoppers int) *StreamProxy

func (*StreamProxy) GetStopCh

func (p *StreamProxy) GetStopCh() chan error

func (*StreamProxy) Serve

func (p *StreamProxy) Serve(client io.ReadWriter, server io.ReadWriter) error

type TerminalSettings

type TerminalSettings struct {
	// The terminal provider may require use of a particular subprotocol. If so,
	// it must be specified here, and Workhorse must have a matching codec.
	Subprotocols []string

	// The websocket URL to connect to.
	Url string

	// Any headers (e.g., Authorization) to send with the websocket request
	Header http.Header

	// The CA roots to validate the remote endpoint with, for wss:// URLs. The
	// system-provided CA pool will be used if this is blank. PEM-encoded data.
	CAPem string

	// The value is specified in seconds. It is converted to time.Duration
	// later.
	MaxSessionTime int
}

func (*TerminalSettings) Clone

func (t *TerminalSettings) Clone() *TerminalSettings

func (*TerminalSettings) Dial

func (*TerminalSettings) Dialer

func (t *TerminalSettings) Dialer() *websocket.Dialer

func (*TerminalSettings) IsEqual

func (t *TerminalSettings) IsEqual(other *TerminalSettings) bool

func (*TerminalSettings) URL

func (t *TerminalSettings) URL() (*url.URL, error)

func (*TerminalSettings) Validate

func (t *TerminalSettings) Validate() error

type WebSocketProxy

type WebSocketProxy struct {
	StopCh chan error
}

func NewWebSocketProxy

func NewWebSocketProxy(stoppers int) *WebSocketProxy

stoppers is the number of goroutines that may attempt to call Stop()

func (*WebSocketProxy) GetStopCh

func (p *WebSocketProxy) GetStopCh() chan error

func (*WebSocketProxy) Serve

func (p *WebSocketProxy) Serve(upstream, downstream Connection, upstreamAddr, downstreamAddr string) error

Jump to

Keyboard shortcuts

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