Documentation ¶
Index ¶
- Constants
- func RegisterPlugin(p *sdk.Plugin, opts PluginOpts) error
- type ClientFactory
- type CommandHandler
- type Handler
- type Manager
- func (m *Manager) AttachSession(_ *types.PluginContext, sessionID string) (*Session, []byte, error)
- func (m *Manager) CloseSession(_ *types.PluginContext, sessionID string) error
- func (m *Manager) CreateSession(pluginctx *types.PluginContext, opts SessionOptions) (*Session, error)
- func (m *Manager) DetachSession(_ *types.PluginContext, sessionID string) (*Session, error)
- func (m *Manager) GetSession(_ *types.PluginContext, sessionID string) (*Session, error)
- func (m *Manager) GetSupportedResources(_ *types.PluginContext) []Handler
- func (m *Manager) ListSessions(_ *types.PluginContext) ([]*Session, error)
- func (m *Manager) ResizeSession(_ *types.PluginContext, sessionID string, rows, cols int32) error
- func (m *Manager) Stream(ctx context.Context, in chan StreamInput) (chan StreamOutput, error)
- type OutputBuffer
- type Plugin
- type PluginClient
- func (c *PluginClient) AttachSession(ctx *types.PluginContext, sessionID string) (*Session, []byte, error)
- func (c *PluginClient) CloseSession(ctx *types.PluginContext, sessionID string) error
- func (c *PluginClient) CreateSession(ctx *types.PluginContext, opts SessionOptions) (*Session, error)
- func (c *PluginClient) DetachSession(ctx *types.PluginContext, sessionID string) (*Session, error)
- func (c *PluginClient) GetSession(ctx *types.PluginContext, sessionID string) (*Session, error)
- func (c *PluginClient) GetSupportedResources(ctx *types.PluginContext) []Handler
- func (c *PluginClient) ListSessions(ctx *types.PluginContext) ([]*Session, error)
- func (c *PluginClient) ResizeSession(ctx *types.PluginContext, sessionID string, cols, rows int32) error
- func (c *PluginClient) Stream(ctx context.Context, in chan StreamInput) (chan StreamOutput, error)
- type PluginOpts
- type PluginServer
- func (s *PluginServer) AttachSession(ctx context.Context, in *proto.AttachSessionRequest) (*proto.AttachSessionResponse, error)
- func (s *PluginServer) CloseSession(ctx context.Context, in *proto.CloseSessionRequest) (*proto.CloseSessionResponse, error)
- func (s *PluginServer) CreateSession(ctx context.Context, in *proto.SessionOptions) (*proto.CreateSessionResponse, error)
- func (s *PluginServer) DetachSession(ctx context.Context, in *proto.AttachSessionRequest) (*proto.AttachSessionResponse, error)
- func (s *PluginServer) GetSession(ctx context.Context, in *proto.GetSessionRequest) (*proto.GetSessionResponse, error)
- func (s *PluginServer) GetSupportedResources(ctx context.Context, _ *emptypb.Empty) (*proto.GetSupportedResourcesResponse, error)
- func (s *PluginServer) ListSessions(ctx context.Context, in *emptypb.Empty) (*proto.ListSessionsResponse, error)
- func (s *PluginServer) ResizeSession(ctx context.Context, in *proto.ResizeSessionRequest) (*proto.ResizeSessionResponse, error)
- func (s *PluginServer) Stream(stream proto.ExecPlugin_StreamServer) error
- type Provider
- type Session
- func (s *Session) Close()
- func (s *Session) GetBufferData() []byte
- func (s *Session) GetCanceller() context.CancelFunc
- func (s *Session) GetPty() *os.File
- func (s *Session) GetTty() *os.File
- func (s *Session) RecordToBuffer(data []byte)
- func (s *Session) SetPty(pty *os.File)
- func (s *Session) SetTty(tty *os.File)
- func (s *Session) ToProto() *proto.Session
- func (s *Session) Write(data []byte) (int, error)
- type SessionHandler
- type SessionOptions
- type SessionResizeInput
- type StreamInput
- type StreamOutput
- type StreamResize
- type StreamSignal
- type StreamTarget
- type TTYHandler
Constants ¶
const ( DefaultOutputBufferSize = 1000000 DefaultStreamBufferSize = 4096 InitialRows = 27 InitialCols = 72 ResizeTimeout = 500 * time.Millisecond )
Variables ¶
This section is empty.
Functions ¶
func RegisterPlugin ¶
func RegisterPlugin( p *sdk.Plugin, opts PluginOpts, ) error
Types ¶
type ClientFactory ¶
type ClientFactory[ClientT any] interface { CreateClient(ctx *types.PluginContext) (*ClientT, error) RefreshClient(ctx *types.PluginContext, client *ClientT) error StartClient(ctx *types.PluginContext, client *ClientT) error StopClient(ctx *types.PluginContext, client *ClientT) error }
type CommandHandler ¶
type CommandHandler func(ctx *types.PluginContext, opts SessionOptions) ( stdout io.Reader, stderr io.Reader, err error, )
CommandHandler is the expected signature for the non-tty handler. It should immediately return it's standard output and error.
type Handler ¶
type Handler struct { Plugin string `json:"plugin"` Resource string `json:"resource"` TargetBuilder sdkresource.ActionTargetBuilder `json:"target_builder"` TTYHandler TTYHandler `json:"-"` CommandHandler CommandHandler `json:"-"` // if the handler supports resizing, it will be sent through the channel instead of the pty file HandlesResize bool `json:"-"` }
Handler handles performs running commands and creating sessions for a resource.
func HandlerFromProto ¶
func HandlerFromProto(p *proto.ExecHandler) Handler
func (Handler) ToProto ¶
func (h Handler) ToProto() *proto.ExecHandler
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages the lifecycle of the terminal sessions.
func NewManager ¶
NewManager initializes a new Manager instance.
func (*Manager) AttachSession ¶
func (m *Manager) AttachSession( _ *types.PluginContext, sessionID string, ) (*Session, []byte, error)
AttachToSession marks a session as attached and returns its current output buffer.
func (*Manager) CloseSession ¶
func (m *Manager) CloseSession(_ *types.PluginContext, sessionID string) error
CloseSession cancels the session's context, effectively terminating its command, and removes it from the manager.
func (*Manager) CreateSession ¶
func (m *Manager) CreateSession( pluginctx *types.PluginContext, opts SessionOptions, ) (*Session, error)
CreateSession creates a new terminal session with a given command.
func (*Manager) DetachSession ¶
DetachFromSession marks a session as not attached, stopping output broadcast.
func (*Manager) GetSession ¶
GetSession returns a session by ID.
func (*Manager) GetSupportedResources ¶
func (m *Manager) GetSupportedResources(_ *types.PluginContext) []Handler
func (*Manager) ListSessions ¶
func (m *Manager) ListSessions(_ *types.PluginContext) ([]*Session, error)
ListSessions returns a list of details for all active sessions.
func (*Manager) ResizeSession ¶
func (m *Manager) ResizeSession( _ *types.PluginContext, sessionID string, rows, cols int32, ) error
ResizeSession resizes a session.
func (*Manager) Stream ¶
func (m *Manager) Stream(ctx context.Context, in chan StreamInput) (chan StreamOutput, error)
Stream creates a new stream to multiplex sessions.
type OutputBuffer ¶
type OutputBuffer struct {
// contains filtered or unexported fields
}
OutputBuffer stores terminal output lines, providing a fixed-size cyclic buffer.
func NewDefaultOutputBuffer ¶
func NewDefaultOutputBuffer() *OutputBuffer
func NewOutputBuffer ¶
func NewOutputBuffer(capacity int) *OutputBuffer
NewOutputBuffer initializes an OutputBuffer with a specified capacity.
func (*OutputBuffer) Append ¶
func (b *OutputBuffer) Append(data []byte)
Append adds a line to the buffer, managing overflow by removing the oldest line.
func (*OutputBuffer) GetAll ¶
func (b *OutputBuffer) GetAll() []byte
GetAll retrieves a copy of all stored lines in the buffer.
type PluginClient ¶
type PluginClient struct {
// contains filtered or unexported fields
}
func (*PluginClient) AttachSession ¶
func (c *PluginClient) AttachSession( ctx *types.PluginContext, sessionID string, ) (*Session, []byte, error)
func (*PluginClient) CloseSession ¶
func (c *PluginClient) CloseSession(ctx *types.PluginContext, sessionID string) error
func (*PluginClient) CreateSession ¶
func (c *PluginClient) CreateSession( ctx *types.PluginContext, opts SessionOptions, ) (*Session, error)
func (*PluginClient) DetachSession ¶
func (c *PluginClient) DetachSession( ctx *types.PluginContext, sessionID string, ) (*Session, error)
func (*PluginClient) GetSession ¶
func (c *PluginClient) GetSession( ctx *types.PluginContext, sessionID string, ) (*Session, error)
func (*PluginClient) GetSupportedResources ¶
func (c *PluginClient) GetSupportedResources(ctx *types.PluginContext) []Handler
func (*PluginClient) ListSessions ¶
func (c *PluginClient) ListSessions(ctx *types.PluginContext) ([]*Session, error)
func (*PluginClient) ResizeSession ¶
func (c *PluginClient) ResizeSession( ctx *types.PluginContext, sessionID string, cols, rows int32, ) error
func (*PluginClient) Stream ¶
func (c *PluginClient) Stream( ctx context.Context, in chan StreamInput, ) (chan StreamOutput, error)
type PluginOpts ¶
type PluginOpts struct {
Handlers []Handler `json:"handlers"`
}
PluginOpts contains the options for the exec plugin.
type PluginServer ¶
type PluginServer struct { Impl Provider // contains filtered or unexported fields }
func (*PluginServer) AttachSession ¶
func (s *PluginServer) AttachSession( ctx context.Context, in *proto.AttachSessionRequest, ) (*proto.AttachSessionResponse, error)
func (*PluginServer) CloseSession ¶
func (s *PluginServer) CloseSession( ctx context.Context, in *proto.CloseSessionRequest, ) (*proto.CloseSessionResponse, error)
func (*PluginServer) CreateSession ¶
func (s *PluginServer) CreateSession( ctx context.Context, in *proto.SessionOptions, ) (*proto.CreateSessionResponse, error)
func (*PluginServer) DetachSession ¶
func (s *PluginServer) DetachSession( ctx context.Context, in *proto.AttachSessionRequest, ) (*proto.AttachSessionResponse, error)
func (*PluginServer) GetSession ¶
func (s *PluginServer) GetSession( ctx context.Context, in *proto.GetSessionRequest, ) (*proto.GetSessionResponse, error)
func (*PluginServer) GetSupportedResources ¶
func (s *PluginServer) GetSupportedResources( ctx context.Context, _ *emptypb.Empty, ) (*proto.GetSupportedResourcesResponse, error)
func (*PluginServer) ListSessions ¶
func (s *PluginServer) ListSessions( ctx context.Context, in *emptypb.Empty, ) (*proto.ListSessionsResponse, error)
func (*PluginServer) ResizeSession ¶
func (s *PluginServer) ResizeSession( ctx context.Context, in *proto.ResizeSessionRequest, ) (*proto.ResizeSessionResponse, error)
func (*PluginServer) Stream ¶
func (s *PluginServer) Stream(stream proto.ExecPlugin_StreamServer) error
type Provider ¶
type Provider interface { // GetSupportedResources returns the supported resource types GetSupportedResources(ctx *types.PluginContext) []Handler // GetSession returns a session by ID GetSession(ctx *types.PluginContext, sessionID string) (*Session, error) // ListSessions returns all of the sessions ListSessions(ctx *types.PluginContext) ([]*Session, error) // CreateSession creates a new session CreateSession(ctx *types.PluginContext, opts SessionOptions) (*Session, error) // AttachSession attaches a session AttachSession(ctx *types.PluginContext, sessionID string) (*Session, []byte, error) // DetachSession detaches a session DetachSession(ctx *types.PluginContext, sessionID string) (*Session, error) // CloseSession closes a session CloseSession(ctx *types.PluginContext, sessionID string) error // ResizeSession resizes a session ResizeSession(ctx *types.PluginContext, sessionID string, cols, rows int32) error // Stream starts a new stream to multiplex sessions Stream(context.Context, chan StreamInput) (chan StreamOutput, error) }
Provider is the interface satisfied by the plugin server and client to provide the exec functionality.
type Session ¶
type Session struct { CreatedAt time.Time `json:"created_at"` Labels map[string]string `json:"labels"` Params map[string]string `json:"params"` ID string `json:"id"` Command []string `json:"command"` Attached bool `json:"attached"` // contains filtered or unexported fields }
Session represents an individual terminal session (shell session with a tty).
func NewSessionFromOpts ¶
func NewSessionFromOpts( ctx context.Context, canceller context.CancelFunc, opts SessionOptions, ) *Session
func NewSessionFromProto ¶
func (*Session) GetBufferData ¶
func (*Session) GetCanceller ¶
func (s *Session) GetCanceller() context.CancelFunc
func (*Session) RecordToBuffer ¶
type SessionHandler ¶
type SessionHandler func(ctx *types.PluginContext, opts SessionOptions) ( stdin io.Writer, stdout io.Reader, stderr io.Reader, err error, )
SessionHandler is the expected signature for a function that creates a new session.
The session handler should start a new session against the given resource and return the standard input, output, and error streams which will be multiplexed to the client.
type SessionOptions ¶
type SessionOptions struct { Params map[string]string `json:"params"` Labels map[string]string `json:"labels"` ID string `json:"id"` ResourcePlugin string `json:"resource_plugin"` ResourceKey string `json:"resource_key"` ResourceData map[string]interface{} `json:"resource_data"` Command []string `json:"command"` TTY bool `json:"tty"` }
SessionOptions contains options for creating a new terminal session.
func NewSessionOptionsFromProto ¶
func NewSessionOptionsFromProto(opts *proto.SessionOptions) *SessionOptions
func (*SessionOptions) ToProto ¶
func (o *SessionOptions) ToProto() *proto.SessionOptions
type SessionResizeInput ¶
type StreamInput ¶
type StreamInput struct { // SessionID SessionID string `json:"session_id"` // Data Data []byte `json:"data"` }
func NewStreamInputFromProto ¶
func NewStreamInputFromProto(p *proto.StreamInput) StreamInput
func (*StreamInput) ToProto ¶
func (i *StreamInput) ToProto() *proto.StreamInput
type StreamOutput ¶
type StreamOutput struct { SessionID string `json:"session_id"` Data []byte `json:"data"` Target StreamTarget `json:"target"` Signal StreamSignal `json:"signal"` }
func NewStreamOutputFromProto ¶
func NewStreamOutputFromProto(p *proto.StreamOutput) StreamOutput
func (*StreamOutput) ToProto ¶
func (o *StreamOutput) ToProto() *proto.StreamOutput
type StreamResize ¶
type StreamResize struct { SessionID string `json:"session_id"` Cols uint16 `json:"cols"` Rows uint16 `json:"rows"` }
func NewStreamResizeFromProto ¶
func NewStreamResizeFromProto(p *proto.ResizeSessionRequest) StreamResize
func (*StreamResize) ToProto ¶
func (r *StreamResize) ToProto() *proto.ResizeSessionRequest
type StreamSignal ¶
type StreamSignal int
const ( // while close isn't a signal, it's used to close the stream. StreamSignalNone StreamSignal = iota StreamSignalClose StreamSignalSigint StreamSignalSigquit StreamSignalSigterm StreamSignalSigkill StreamSignalSighup StreamSignalSigusr1 StreamSignalSigusr2 StreamSignalSigwinch )
func NewStreamSignalFromProto ¶
func NewStreamSignalFromProto(p proto.StreamSignal) StreamSignal
func (StreamSignal) String ¶
func (s StreamSignal) String() string
func (StreamSignal) ToProto ¶
func (s StreamSignal) ToProto() proto.StreamSignal
pointer receiver to allow nil signal (when none is actually sent).
type StreamTarget ¶
type StreamTarget int
const ( StreamTargetStdOut StreamTarget = iota StreamTargetStdErr )
func (StreamTarget) String ¶
func (t StreamTarget) String() string
type TTYHandler ¶
type TTYHandler func(ctx *types.PluginContext, opts SessionOptions, tty *os.File, stopCh chan struct{}, resize <-chan SessionResizeInput) error
TTYHandler is the expected signature for a function that creates a new session with a TTY. It is passed the TTY file descriptor for the session, and a resize channel that will receive resize events for the TTY, of which.