Documentation ¶
Index ¶
- func CreateKeyPair() (publicKeyBytes []byte, privateKeyBytes []byte, err error)
- func CreateTempFileFromString(content string, filemode os.FileMode) (*os.File, error)
- func ExtractRetCode(err error) (string, int, error)
- func GetBashLibrary() (string, error)
- func IsSCPRetryable(code int) bool
- func IsSSHRetryable(code int) bool
- func SCPErrorString(retcode int) string
- func SSHErrorString(retcode int) string
- type SSHCommand
- func (sc *SSHCommand) CombinedOutput() ([]byte, error)
- func (sc *SSHCommand) Display() string
- func (sc *SSHCommand) Kill() error
- func (sc *SSHCommand) Output() ([]byte, error)
- func (sc *SSHCommand) Run(t concurrency.Task) (int, string, string, error)
- func (sc *SSHCommand) RunWithTimeout(t concurrency.Task, timeout time.Duration) (int, string, string, error)
- func (sc *SSHCommand) Start() error
- func (sc *SSHCommand) StderrPipe() (io.ReadCloser, error)
- func (sc *SSHCommand) StdinPipe() (io.WriteCloser, error)
- func (sc *SSHCommand) StdoutPipe() (io.ReadCloser, error)
- func (sc *SSHCommand) Wait() error
- type SSHConfig
- func (ssh *SSHConfig) Command(cmdString string) (*SSHCommand, error)
- func (ssh *SSHConfig) CommandContext(ctx context.Context, cmdString string) (*SSHCommand, error)
- func (ssh *SSHConfig) Copy(remotePath, localPath string, isUpload bool) (int, string, string, error)
- func (ssh *SSHConfig) CreateTunneling() ([]*SSHTunnel, *SSHConfig, error)
- func (ssh *SSHConfig) Enter() error
- func (ssh *SSHConfig) Exec(cmdString string) error
- func (ssh *SSHConfig) SudoCommand(cmdString string) (*SSHCommand, error)
- func (ssh *SSHConfig) WaitServerReady(phase string, timeout time.Duration) (out string, err error)
- type SSHTunnel
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateKeyPair ¶
CreateKeyPair creates a key pair
func CreateTempFileFromString ¶
CreateTempFileFromString creates a temporary file containing 'content'
func ExtractRetCode ¶
ExtractRetCode extracts info from the error
func GetBashLibrary ¶
GetBashLibrary generates the content of {{.reserved_BashLibrary}}
func IsSCPRetryable ¶
IsSCPRetryable tells if the retcode of a scp command may be retried
func IsSSHRetryable ¶
IsSSHRetryable tells if the retcode of a ssh command may be retried
func SCPErrorString ¶
SCPErrorString returns if possible the string corresponding to SCP execution
func SSHErrorString ¶
SSHErrorString returns if possible the string corresponding to SSH execution
Types ¶
type SSHCommand ¶
type SSHCommand struct {
// contains filtered or unexported fields
}
SSHCommand defines a SSH command
func (*SSHCommand) CombinedOutput ¶
func (sc *SSHCommand) CombinedOutput() ([]byte, error)
CombinedOutput runs the command and returns its combined standard output and standard error.
func (*SSHCommand) Kill ¶
func (sc *SSHCommand) Kill() error
Kill kills SSHCommand process and releases any resources associated with the SSHCommand.
func (*SSHCommand) Output ¶
func (sc *SSHCommand) Output() ([]byte, error)
Output runs the command and returns its standard output. Any returned error will usually be of type *ExitError. If c.Stderr was nil, Output populates ExitError.Stderr.
func (*SSHCommand) Run ¶
func (sc *SSHCommand) Run(t concurrency.Task) (int, string, string, error)
Run starts the specified command and waits for it to complete.
The returned error is nil if the command runs, has no problems copying stdin, stdout, and stderr, and exits with a zero exit status.
If the command starts but does not complete successfully, the error is of type *ExitError. Other error types may be returned for other situations.
func (*SSHCommand) RunWithTimeout ¶
func (sc *SSHCommand) RunWithTimeout(t concurrency.Task, timeout time.Duration) (int, string, string, error)
RunWithTimeout ...
func (*SSHCommand) Start ¶
func (sc *SSHCommand) Start() error
Start starts the specified command but does not wait for it to complete.
The Wait method will return the exit code and release associated resources once the command exits.
func (*SSHCommand) StderrPipe ¶
func (sc *SSHCommand) StderrPipe() (io.ReadCloser, error)
StderrPipe returns a pipe that will be connected to the command's standard error when the command starts. Wait will close the pipe after seeing the command exit, so most callers need not close the pipe themselves; however, an implication is that it is incorrect to call Wait before all reads from the pipe have completed. For the same reason, it is incorrect to use Run when using StderrPipe.
func (*SSHCommand) StdinPipe ¶
func (sc *SSHCommand) StdinPipe() (io.WriteCloser, error)
StdinPipe returns a pipe that will be connected to the command's standard input when the command starts. The pipe will be closed automatically after Wait sees the command exit. A caller need only call Close to force the pipe to close sooner. For example, if the command being run will not exit until standard input is closed, the caller must close the pipe.
func (*SSHCommand) StdoutPipe ¶
func (sc *SSHCommand) StdoutPipe() (io.ReadCloser, error)
StdoutPipe returns a pipe that will be connected to the command's standard output when the command starts. Wait will close the pipe after seeing the command exit, so most callers need not close the pipe themselves; however, an implication is that it is incorrect to call Wait before all reads from the pipe have completed. For the same reason, it is incorrect to call Run when using StdoutPipe.
func (*SSHCommand) Wait ¶
func (sc *SSHCommand) Wait() error
Wait waits for the command to exit and waits for any copying to stdin or copying from stdout or stderr to complete. The command must have been started by Start. The returned error is nil if the command runs, has no problems copying stdin, stdout, and stderr, and exits with a zero exit status. If the command fails to run or doesn't complete successfully, the error is of type *ExitError. Other error types may be returned for I/O problems. Wait also waits for the I/O loop copying from c.Stdin into the process's standard input to complete. Wait releases any resources associated with the cmd.
type SSHConfig ¶
type SSHConfig struct { User string Host string PrivateKey string Port int LocalPort int GatewayConfig *SSHConfig // contains filtered or unexported fields }
SSHConfig helper to manage ssh session
func (*SSHConfig) Command ¶
func (ssh *SSHConfig) Command(cmdString string) (*SSHCommand, error)
Command returns the cmd struct to execute cmdString remotely
func (*SSHConfig) CommandContext ¶
CommandContext is like Command but includes a context.
The provided context is used to kill the process (by calling os.Process.Kill) if the context becomes done before the command completes on its own.
func (*SSHConfig) Copy ¶
func (ssh *SSHConfig) Copy(remotePath, localPath string, isUpload bool) (int, string, string, error)
Copy copies a file/directory from/to local to/from remote
func (*SSHConfig) CreateTunneling ¶
CreateTunneling ...
func (*SSHConfig) SudoCommand ¶
func (ssh *SSHConfig) SudoCommand(cmdString string) (*SSHCommand, error)
SudoCommand returns the cmd struct to execute cmdString remotely. Command is executed with sudo