executor

package
v0.0.0-...-05fba6c Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2022 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Bash  = &ContentType{"text", "bash", map[string]string{}}
	Shell = &ContentType{"text", "shell", map[string]string{}}
)
View Source
var (
	ErrUnsupportedContentType = errors.New("unsupported content-type")
	ErrExecInProgress         = errors.New("an execution is already in progress")
)
View Source
var MySQL = &ContentType{"text", "mysql", map[string]string{}}
View Source
var PSQL = &ContentType{"text", "psql", map[string]string{}}

Functions

func DisablePTY

func DisablePTY()

Types

type BaseExecutor

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

func (*BaseExecutor) Cleanup

func (be *BaseExecutor) Cleanup()

func (*BaseExecutor) ContentType

func (be *BaseExecutor) ContentType() *ContentType

func (*BaseExecutor) Execute

func (be *BaseExecutor) Execute(ctx context.Context, req *ExecRequest) *ExecResponse

func (*BaseExecutor) Name

func (be *BaseExecutor) Name() string

type BashExecutor

type BashExecutor struct {
	BaseExecutor
	// contains filtered or unexported fields
}

type Canceler

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

func (*Canceler) OnCancel

func (clr *Canceler) OnCancel(cb func())

func (*Canceler) Stop

func (clr *Canceler) Stop()

type CommandFeeder

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

func NewCommandFeeder

func NewCommandFeeder(inputWriter io.WriteCloser) *CommandFeeder

func (*CommandFeeder) Close

func (cf *CommandFeeder) Close() error

func (*CommandFeeder) Put

func (cf *CommandFeeder) Put(content []byte)

func (*CommandFeeder) Read

func (cf *CommandFeeder) Read(buf []byte) (int, error)

func (*CommandFeeder) Write

func (cf *CommandFeeder) Write(p []byte) (int, error)

type ContentType

type ContentType struct {
	Type    string
	Subtype string
	Params  map[string]string
}

func NewContentType

func NewContentType(language string, params map[string]string) *ContentType

func Parse

func Parse(val string) (*ContentType, error)

func (*ContentType) Clone

func (ct *ContentType) Clone() *ContentType

func (*ContentType) MarshalJSON

func (ct *ContentType) MarshalJSON() ([]byte, error)

func (*ContentType) ParentOf

func (ct *ContentType) ParentOf(other *ContentType, requiredKeys []string) bool

ParentOf returns true when the other content-type matches but may have more specific parameters (i.e. this content-type is a "parent" of the other).

func (*ContentType) String

func (ct *ContentType) String() string

func (*ContentType) UnmarshalJSON

func (ct *ContentType) UnmarshalJSON(data []byte) error

type ExecRequest

type ExecRequest struct {
	Hdr *RequestHdr

	// Content refers to the payload provided by the requester
	Content []byte

	// ContentType refers to the MIME type of the content
	ContentType *ContentType

	// In represents the additional input provided by the requester,
	// a side-effect. This is in-addition to the regular input provided
	// by the Content byte array.
	// Example: In a shell command execution (i.e ContentType=text/bash).
	// Content can be process command line, while In could represents the stdin.
	In *os.File

	// the executor publishes all side effects (Stdout, Stderr, debugging events etc.)
	Stdout io.WriteCloser
	Stderr io.WriteCloser
}

func DefaultRequest

func DefaultRequest() *ExecRequest

type ExecResponse

type ExecResponse struct {
	Hdr *ResponseHdr

	// Exit status of the command
	ExitStatus int

	// Err is set to non-nil on error/cancellation
	Err error
}

type Executor

type Executor interface {
	Name() string

	// ContentType returns the content type supported by the Executor
	ContentType() *ContentType

	// Execute requests the Executor to execute the provided request
	Execute(context.Context, *ExecRequest) *ExecResponse

	// Cleanup is the Internal function invoked when the Register is torn down
	Cleanup()
}

func NewBashExecutor

func NewBashExecutor(content []byte, contentType *ContentType) (Executor, error)

func NewMySQLExecutor

func NewMySQLExecutor(content []byte, contentType *ContentType) (Executor, error)

func NewPSQLExecutor

func NewPSQLExecutor(content []byte, contentType *ContentType) (Executor, error)

func NewRemoteShellExecutor

func NewRemoteShellExecutor(content []byte, contentType *ContentType) (Executor, error)

func NewWinBashExecutor

func NewWinBashExecutor(content []byte, contentType *ContentType) (Executor, error)

type IgnoreCloseWriter

type IgnoreCloseWriter struct {
	Writer io.Writer
}

func (*IgnoreCloseWriter) Close

func (icw *IgnoreCloseWriter) Close() error

func (*IgnoreCloseWriter) Write

func (icw *IgnoreCloseWriter) Write(data []byte) (int, error)

type MySQLExecutor

type MySQLExecutor struct {
	BaseExecutor
}

type PSQLExecutor

type PSQLExecutor struct {
	BaseExecutor
}

type Register

type Register struct {
	sync.Map
}

func NewRegister

func NewRegister() (*Register, error)

func (*Register) Cleanup

func (r *Register) Cleanup()

func (*Register) Execute

func (r *Register) Execute(ctx context.Context, req *ExecRequest) *ExecResponse

func (*Register) Get

func (r *Register) Get(content []byte, contentType *ContentType) (Executor, error)

func (*Register) Register

func (r *Register) Register(executor Executor) error

type RemoteShellExecutor

type RemoteShellExecutor struct {
	BaseExecutor
}

type RequestHdr

type RequestHdr struct {
	// A unique ID, identifying request
	ID string
	// ExecutionID uniquely identifies a playbook execution
	ExecutionID string
	// NodeID identifies the node being execution
	NodeID string
	// UserID identifies the user executing the run
	UserID string
}

type ResponseHdr

type ResponseHdr struct {
	// RequestID refers to request's unique ID
	RequestID string
}

type WinBashExecutor

type WinBashExecutor struct {
	BaseExecutor
}

Jump to

Keyboard shortcuts

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