executor

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2023 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrPropSSHCommand is ErrPropSSHCommand
	ErrPropSSHCommand = errorx.RegisterPrintableProperty("ssh_command")
	// ErrPropSSHStdout is ErrPropSSHStdout
	ErrPropSSHStdout = errorx.RegisterPrintableProperty("ssh_stdout")
	// ErrPropSSHStderr is ErrPropSSHStderr
	ErrPropSSHStderr = errorx.RegisterPrintableProperty("ssh_stderr")

	// ErrSSHExecuteFailed is ErrSSHExecuteFailed
	ErrSSHExecuteFailed = errNSSSH.NewType("execute_failed")
	// ErrSSHExecuteTimedout is ErrSSHExecuteTimedout
	ErrSSHExecuteTimedout = errNSSSH.NewType("execute_timedout")
)

Functions

func FindSSHAuthorizedKeysFile

func FindSSHAuthorizedKeysFile(ctx context.Context, exec ctxt.Executor) string

FindSSHAuthorizedKeysFile finds the correct path of SSH authorized keys file

func New

func New(etype SSHType, sudo bool, c SSHConfig, env []string) (ctxt.Executor, error)

New create a new Executor

func ScpDownload

func ScpDownload(session *ssh.Session, client *ssh.Client, src, dst string, limit int) error

ScpDownload downloads a file from remote with SCP The implementation is partially inspired by github.com/dtylman/scp

Types

type CheckPointExecutor

type CheckPointExecutor struct {
	ctxt.Executor
	// contains filtered or unexported fields
}

CheckPointExecutor wraps Executor and inject checkpoints

ATTENTION please: the result of CheckPointExecutor shouldn't be used to impact
                  external system like PD, otherwise, the external system may
                  take wrong action.

func (*CheckPointExecutor) Execute

func (c *CheckPointExecutor) Execute(ctx context.Context, cmd string, sudo bool, timeout ...time.Duration) (stdout []byte, stderr []byte, err error)

Execute implements Executor interface.

func (*CheckPointExecutor) Transfer

func (c *CheckPointExecutor) Transfer(ctx context.Context, src, dst string, download bool, limit int) (err error)

Transfer implements Executer interface.

type EasySSHExecutor

type EasySSHExecutor struct {
	Config *easyssh.MakeConfig
	Locale string   // the locale used when executing the command
	Sudo   bool     // all commands run with this executor will be using sudo
	Env    []string // env used to be transferred
}

EasySSHExecutor implements Executor with EasySSH as transportation layer.

func (*EasySSHExecutor) Execute

func (e *EasySSHExecutor) Execute(ctx context.Context, cmd string, sudo bool, timeout ...time.Duration) ([]byte, []byte, error)

Execute run the command via SSH, it's not invoking any specific shell by default.

func (*EasySSHExecutor) Transfer

func (e *EasySSHExecutor) Transfer(ctx context.Context, src, dst string, download bool, limit int) error

Transfer copies files via SCP This function depends on `scp` (a tool from OpenSSH or other SSH implementation) This function is based on easyssh.MakeConfig.Scp() but with support of copying file from remote to local.

func (*EasySSHExecutor) TransferTemplate

func (e *EasySSHExecutor) TransferTemplate(ctx context.Context, templateFile, dst, fileMode string, config interface{}, sudo bool, limit int) error

type Local

type Local struct {
	Config *SSHConfig
	Sudo   bool     // all commands run with this executor will be using sudo
	Locale string   // the locale used when executing the command
	Env    []string // env used to be transferred
}

Local execute the command at local host.

func (*Local) Execute

func (l *Local) Execute(ctx context.Context, cmd string, sudo bool, timeout ...time.Duration) ([]byte, []byte, error)

Execute implements Executor interface.

func (*Local) Transfer

func (l *Local) Transfer(ctx context.Context, src, dst string, download bool, limit int) error

Transfer implements Executer interface.

func (*Local) TransferTemplate

func (l *Local) TransferTemplate(ctx context.Context, templateFile, dst, fileMode string, config interface{}, sudo bool, limit int) error

type NativeSSHExecutor

type NativeSSHExecutor struct {
	Config               *SSHConfig
	Locale               string   // the locale used when executing the command
	Sudo                 bool     // all commands run with this executor will be using sudo
	Env                  []string // env used to be transferred
	ConnectionTestResult error    // test if the connection can be established in initialization phase
}

NativeSSHExecutor implements Excutor with native SSH transportation layer.

func (*NativeSSHExecutor) Execute

func (e *NativeSSHExecutor) Execute(ctx context.Context, cmd string, sudo bool, timeout ...time.Duration) ([]byte, []byte, error)

Execute run the command via SSH, it's not invoking any specific shell by default.

func (*NativeSSHExecutor) Transfer

func (e *NativeSSHExecutor) Transfer(ctx context.Context, src, dst string, download bool, limit int) error

Transfer copies files via SCP This function depends on `scp` (a tool from OpenSSH or other SSH implementation)

func (*NativeSSHExecutor) TransferTemplate

func (e *NativeSSHExecutor) TransferTemplate(ctx context.Context, templateFile, dst, fileMode string, config interface{}, sudo bool, limit int) error

type SSHConfig

type SSHConfig struct {
	Host       string        // hostname of the SSH server
	Port       int           // port of the SSH server
	User       string        // username to login to the SSH server
	Password   string        // password of the user
	KeyFile    string        // path to the private key file
	Passphrase string        // passphrase of the private key file
	Timeout    time.Duration // Timeout is the maximum amount of time for the TCP connection to establish.
	ExeTimeout time.Duration // ExeTimeout is the maximum amount of time for the command to finish
	Proxy      *SSHConfig    // ssh proxy config
}

SSHConfig is the configuration needed to establish SSH connection.

type SSHType

type SSHType string

SSHType represent the type of the chanel used by ssh

var (

	// SSHTypeBuiltin is the type of easy ssh executor
	SSHTypeBuiltin SSHType = "builtin"

	// SSHTypeSystem is the type of host ssh client
	SSHTypeSystem SSHType = "system"

	// SSHTypeNone is the type of local executor (no ssh will be used)
	SSHTypeNone SSHType = "none"
)

Jump to

Keyboard shortcuts

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