{"modulePath":"github.com/omniviewdev/plugin-sdk","version":"v0.1.2","isLatest":false,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package exec\n\n## Constants\n\n```go\nconst (\n\tDefaultOutputBufferSize = 1000000\n\tDefaultStreamBufferSize = 4096\n\tInitialRows             = 27\n\tInitialCols             = 72\n\tResizeTimeout           = 500 * time.Millisecond\n)\n```\n\n## Functions\n\n```go\nfunc RegisterPlugin(\n\tp *sdk.Plugin,\n\topts PluginOpts,\n) error\n```\n\n## Types\n\n```go\ntype ClientFactory[ClientT any] interface {\n\tCreateClient(ctx *types.PluginContext) (*ClientT, error)\n\tRefreshClient(ctx *types.PluginContext, client *ClientT) error\n\tStartClient(ctx *types.PluginContext, client *ClientT) error\n\tStopClient(ctx *types.PluginContext, client *ClientT) error\n}\n```\n\n```go\ntype CommandHandler func(ctx *types.PluginContext, opts SessionOptions) (\n\tstdout io.Reader,\n\tstderr io.Reader,\n\terr error,\n)\n```\nCommandHandler is the expected signature for the non-tty handler. It should immediately return it's standard output and error.\n\n```go\ntype ExecError struct {\n\tErr           error\n\tTitle         string\n\tMessage       string\n\tSuggestion    string\n\tRetryable     bool\n\tRetryCommands []string\n}\n```\nExecError is a structured error type that plugins use to provide classified exec errors with user-facing information.\n\n```go\nfunc (e *ExecError) Error() string\n```\n\n```go\nfunc (e *ExecError) Unwrap() error\n```\n\n```go\ntype Handler struct {\n\tPlugin         string                          `json:\"plugin\"`\n\tResource       string                          `json:\"resource\"`\n\tTargetBuilder  sdkresource.ActionTargetBuilder `json:\"target_builder\"`\n\tDefaultCommand []string                        `json:\"default_command\"`\n\tTTYHandler     TTYHandler                      `json:\"-\"`\n\tCommandHandler CommandHandler                  `json:\"-\"`\n\t// if the handler supports resizing, it will be sent through the channel instead of the pty file\n\tHandlesResize bool `json:\"-\"`\n}\n```\nHandler handles performs running commands and creating sessions for a resource.\n\n```go\nfunc HandlerFromProto(p *proto.ExecHandler) Handler\n```\n\n```go\nfunc (h Handler) ID() string\n```\n\n```go\nfunc (h Handler) String() string\n```\n\n```go\nfunc (h Handler) ToProto() *proto.ExecHandler\n```\n\n```go\ntype Manager struct {\n\t// contains filtered or unexported fields\n}\n```\nManager manages the lifecycle of the terminal sessions.\n\n```go\nfunc NewManager(\n\tlog hclog.Logger,\n\tsp settings.Provider,\n\thandlers map[string]Handler,\n) *Manager\n```\nNewManager initializes a new Manager instance.\n\n```go\nfunc (m *Manager) AttachSession(\n\t_ *types.PluginContext,\n\tsessionID string,\n) (*Session, []byte, error)\n```\nAttachToSession marks a session as attached and returns its current output buffer.\n\n```go\nfunc (m *Manager) CloseSession(_ *types.PluginContext, sessionID string) error\n```\nCloseSession cancels the session's context, effectively terminating its command, and removes it from the manager.\n\n```go\nfunc (m *Manager) CreateSession(\n\tpluginctx *types.PluginContext,\n\topts SessionOptions,\n) (*Session, error)\n```\nCreateSession creates a new terminal session with a given command.\n\n```go\nfunc (m *Manager) DetachSession(_ *types.PluginContext, sessionID string) (*Session, error)\n```\nDetachFromSession marks a session as not attached, stopping output broadcast.\n\n```go\nfunc (m *Manager) GetSession(\n\t_ *types.PluginContext,\n\tsessionID string,\n) (*Session, error)\n```\nGetSession returns a session by ID.\n\n```go\nfunc (m *Manager) GetSupportedResources(_ *types.PluginContext) []Handler\n```\n\n```go\nfunc (m *Manager) ListSessions(_ *types.PluginContext) ([]*Session, error)\n```\nListSessions returns a list of details for all active sessions.\n\n```go\nfunc (m *Manager) ResizeSession(\n\t_ *types.PluginContext,\n\tsessionID string,\n\trows, cols int32,\n) error\n```\nResizeSession resizes a session.\n\n```go\nfunc (m *Manager) Stream(ctx context.Context, in chan StreamInput) (chan StreamOutput, error)\n```\nStream creates a new stream to multiplex sessions.\n\n```go\ntype OutputBuffer struct {\n\t// contains filtered or unexported fields\n}\n```\nOutputBuffer stores terminal output lines, providing a fixed-size cyclic buffer.\n\n```go\nfunc NewDefaultOutputBuffer() *OutputBuffer\n```\n\n```go\nfunc NewOutputBuffer(capacity int) *OutputBuffer\n```\nNewOutputBuffer initializes an OutputBuffer with a specified capacity.\n\n```go\nfunc (b *OutputBuffer) Append(data []byte)\n```\nAppend adds a line to the buffer, managing overflow by removing the oldest line.\n\n```go\nfunc (b *OutputBuffer) GetAll() []byte\n```\nGetAll retrieves a copy of all stored lines in the buffer.\n\n```go\ntype Plugin struct {\n\tplugin.Plugin\n\tImpl Provider\n}\n```\n\n```go\nfunc (p *Plugin) GRPCClient(\n\t_ context.Context,\n\t_ *plugin.GRPCBroker,\n\tc *grpc.ClientConn,\n) (interface{}, error)\n```\n\n```go\nfunc (p *Plugin) GRPCServer(_ *plugin.GRPCBroker, s *grpc.Server) error\n```\n\n```go\ntype PluginClient struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc (c *PluginClient) AttachSession(\n\tctx *types.PluginContext,\n\tsessionID string,\n) (*Session, []byte, error)\n```\n\n```go\nfunc (c *PluginClient) CloseSession(ctx *types.PluginContext, sessionID string) error\n```\n\n```go\nfunc (c *PluginClient) CreateSession(\n\tctx *types.PluginContext,\n\topts SessionOptions,\n) (*Session, error)\n```\n\n```go\nfunc (c *PluginClient) DetachSession(\n\tctx *types.PluginContext,\n\tsessionID string,\n) (*Session, error)\n```\n\n```go\nfunc (c *PluginClient) GetSession(\n\tctx *types.PluginContext,\n\tsessionID string,\n) (*Session, error)\n```\n\n```go\nfunc (c *PluginClient) GetSupportedResources(ctx *types.PluginContext) []Handler\n```\n\n```go\nfunc (c *PluginClient) ListSessions(ctx *types.PluginContext) ([]*Session, error)\n```\n\n```go\nfunc (c *PluginClient) ResizeSession(\n\tctx *types.PluginContext,\n\tsessionID string,\n\tcols, rows int32,\n) error\n```\n\n```go\nfunc (c *PluginClient) Stream(\n\tctx context.Context,\n\tin chan StreamInput,\n) (chan StreamOutput, error)\n```\n\n```go\ntype PluginOpts struct {\n\tHandlers []Handler `json:\"handlers\"`\n}\n```\nPluginOpts contains the options for the exec plugin.\n\n```go\ntype PluginServer struct {\n\tproto.UnimplementedExecPluginServer\n\n\tImpl Provider\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc (s *PluginServer) AttachSession(\n\tctx context.Context,\n\tin *proto.AttachSessionRequest,\n) (*proto.AttachSessionResponse, error)\n```\n\n```go\nfunc (s *PluginServer) CloseSession(\n\tctx context.Context,\n\tin *proto.CloseSessionRequest,\n) (*proto.CloseSessionResponse, error)\n```\n\n```go\nfunc (s *PluginServer) CreateSession(\n\tctx context.Context,\n\tin *proto.SessionOptions,\n) (*proto.CreateSessionResponse, error)\n```\n\n```go\nfunc (s *PluginServer) DetachSession(\n\tctx context.Context,\n\tin *proto.AttachSessionRequest,\n) (*proto.AttachSessionResponse, error)\n```\n\n```go\nfunc (s *PluginServer) GetSession(\n\tctx context.Context,\n\tin *proto.GetSessionRequest,\n) (*proto.GetSessionResponse, error)\n```\n\n```go\nfunc (s *PluginServer) GetSupportedResources(\n\tctx context.Context,\n\t_ *emptypb.Empty,\n) (*proto.GetSupportedResourcesResponse, error)\n```\n\n```go\nfunc (s *PluginServer) ListSessions(\n\tctx context.Context,\n\tin *emptypb.Empty,\n) (*proto.ListSessionsResponse, error)\n```\n\n```go\nfunc (s *PluginServer) ResizeSession(\n\tctx context.Context,\n\tin *proto.ResizeSessionRequest,\n) (*proto.ResizeSessionResponse, error)\n```\n\n```go\nfunc (s *PluginServer) Stream(stream proto.ExecPlugin_StreamServer) error\n```\n\n```go\ntype Provider interface {\n\t// GetSupportedResources returns the supported resource types\n\tGetSupportedResources(ctx *types.PluginContext) []Handler\n\t// GetSession returns a session by ID\n\tGetSession(ctx *types.PluginContext, sessionID string) (*Session, error)\n\t// ListSessions returns all of the sessions\n\tListSessions(ctx *types.PluginContext) ([]*Session, error)\n\t// CreateSession creates a new session\n\tCreateSession(ctx *types.PluginContext, opts SessionOptions) (*Session, error)\n\t// AttachSession attaches a session\n\tAttachSession(ctx *types.PluginContext, sessionID string) (*Session, []byte, error)\n\t// DetachSession detaches a session\n\tDetachSession(ctx *types.PluginContext, sessionID string) (*Session, error)\n\t// CloseSession closes a session\n\tCloseSession(ctx *types.PluginContext, sessionID string) error\n\t// ResizeSession resizes a session\n\tResizeSession(ctx *types.PluginContext, sessionID string, cols, rows int32) error\n\t// Stream starts a new stream to multiplex sessions\n\tStream(context.Context, chan StreamInput) (chan StreamOutput, error)\n}\n```\nProvider is the interface satisfied by the plugin server and client to provide the exec functionality.\n\n```go\ntype Session struct {\n\tCreatedAt time.Time `json:\"created_at\"`\n\n\tLabels   map[string]string `json:\"labels\"`\n\tParams   map[string]string `json:\"params\"`\n\tID       string            `json:\"id\"`\n\tCommand  []string          `json:\"command\"`\n\tAttached bool              `json:\"attached\"`\n\t// contains filtered or unexported fields\n}\n```\nSession represents an individual terminal session (shell session with a tty).\n\n```go\nfunc NewSessionFromOpts(\n\tctx context.Context,\n\tcanceller context.CancelFunc,\n\topts SessionOptions,\n) *Session\n```\n\n```go\nfunc NewSessionFromProto(s *proto.Session) *Session\n```\n\n```go\nfunc (s *Session) Close()\n```\n\n```go\nfunc (s *Session) GetBufferData() []byte\n```\n\n```go\nfunc (s *Session) GetCanceller() context.CancelFunc\n```\n\n```go\nfunc (s *Session) GetPty() *os.File\n```\n\n```go\nfunc (s *Session) GetTty() *os.File\n```\n\n```go\nfunc (s *Session) RecordToBuffer(data []byte)\n```\n\n```go\nfunc (s *Session) SetPty(pty *os.File)\n```\n\n```go\nfunc (s *Session) SetTty(tty *os.File)\n```\n\n```go\nfunc (s *Session) ToProto() *proto.Session\n```\n\n```go\nfunc (s *Session) Write(data []byte) (int, error)\n```\n\n```go\ntype SessionHandler func(ctx *types.PluginContext, opts SessionOptions) (\n\tstdin io.Writer,\n\tstdout io.Reader,\n\tstderr io.Reader,\n\terr error,\n)\n```\nSessionHandler is the expected signature for a function that creates a new session.\n\nThe 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.\n\n```go\ntype SessionOptions struct {\n\tParams         map[string]string      `json:\"params\"`\n\tLabels         map[string]string      `json:\"labels\"`\n\tID             string                 `json:\"id\"`\n\tResourcePlugin string                 `json:\"resource_plugin\"`\n\tResourceKey    string                 `json:\"resource_key\"`\n\tResourceData   map[string]interface{} `json:\"resource_data\"`\n\tCommand        []string               `json:\"command\"`\n\tTTY            bool                   `json:\"tty\"`\n}\n```\nSessionOptions contains options for creating a new terminal session.\n\n```go\nfunc NewSessionOptionsFromProto(opts *proto.SessionOptions) *SessionOptions\n```\n\n```go\nfunc (o *SessionOptions) ToProto() *proto.SessionOptions\n```\n\n```go\ntype SessionResizeInput struct {\n\tRows int32 `json:\"rows\"`\n\tCols int32 `json:\"cols\"`\n}\n```\n\n```go\ntype StreamError struct {\n\tTitle         string   `json:\"title\"`\n\tMessage       string   `json:\"message\"`\n\tSuggestion    string   `json:\"suggestion\"`\n\tRetryable     bool     `json:\"retryable\"`\n\tRetryCommands []string `json:\"retry_commands,omitempty\"`\n}\n```\nStreamError contains structured error information from a failed exec session.\n\n```go\nfunc NewStreamErrorFromProto(p *proto.StreamError) *StreamError\n```\n\n```go\nfunc (e *StreamError) ToProto() *proto.StreamError\n```\n\n```go\ntype StreamInput struct {\n\t// SessionID\n\tSessionID string `json:\"session_id\"`\n\t// Data\n\tData []byte `json:\"data\"`\n}\n```\n\n```go\nfunc NewStreamInputFromProto(p *proto.StreamInput) StreamInput\n```\n\n```go\nfunc (i *StreamInput) ToProto() *proto.StreamInput\n```\n\n```go\ntype StreamOutput struct {\n\tSessionID string       `json:\"session_id\"`\n\tData      []byte       `json:\"data\"`\n\tTarget    StreamTarget `json:\"target\"`\n\tSignal    StreamSignal `json:\"signal\"`\n\tError     *StreamError `json:\"error,omitempty\"`\n}\n```\n\n```go\nfunc NewStreamOutputFromProto(p *proto.StreamOutput) StreamOutput\n```\n\n```go\nfunc (o *StreamOutput) ToProto() *proto.StreamOutput\n```\n\n```go\ntype StreamResize struct {\n\tSessionID string `json:\"session_id\"`\n\tCols      uint16 `json:\"cols\"`\n\tRows      uint16 `json:\"rows\"`\n}\n```\n\n```go\nfunc NewStreamResizeFromProto(p *proto.ResizeSessionRequest) StreamResize\n```\n\n```go\nfunc (r *StreamResize) ToProto() *proto.ResizeSessionRequest\n```\n\n```go\ntype StreamSignal int\n```\n\n```go\nconst (\n\t// while close isn't a signal, it's used to close the stream.\n\tStreamSignalNone StreamSignal = iota\n\tStreamSignalClose\n\tStreamSignalSigint\n\tStreamSignalSigquit\n\tStreamSignalSigterm\n\tStreamSignalSigkill\n\tStreamSignalSighup\n\tStreamSignalSigusr1\n\tStreamSignalSigusr2\n\tStreamSignalSigwinch\n\tStreamSignalError\n)\n```\n\n```go\nfunc NewStreamSignalFromProto(p proto.StreamSignal) StreamSignal\n```\n\n```go\nfunc (s StreamSignal) String() string\n```\n\n```go\nfunc (s StreamSignal) ToProto() proto.StreamSignal\n```\npointer receiver to allow nil signal (when none is actually sent).\n\n```go\ntype StreamTarget int\n```\n\n```go\nconst (\n\tStreamTargetStdOut StreamTarget = iota\n\tStreamTargetStdErr\n)\n```\n\n```go\nfunc (t StreamTarget) String() string\n```\n\n```go\ntype TTYHandler func(ctx *types.PluginContext, opts SessionOptions, tty *os.File, stopCh chan error, resize \u003c-chan SessionResizeInput) error\n```\nTTYHandler 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.\n\n","path":"github.com/omniviewdev/plugin-sdk/pkg/exec","name":"exec","synopsis":"","isRedistributable":true}
