Documentation ¶
Index ¶
- Constants
- func CheckTimeSync(ctx context.Context, nodes []SshNode) error
- func Client(addr, user string, signer ssh.Signer) (*ssh.Client, error)
- func Connect(addr, user string, signer ssh.Signer) (*ssh.Session, error)
- func IsExitMissingError(err error) bool
- func MakePrivateKeySignerFromFile(path string) (ssh.Signer, error)
- func MakePrivateKeySignerFromReader(r io.Reader) (ssh.Signer, error)
- func ParseDiscard(r *bufio.Reader) error
- func PipeCommand(ctx context.Context, client *ssh.Client, log logrus.FieldLogger, ...) error
- func PutFile(ctx context.Context, client *ssh.Client, log logrus.FieldLogger, ...) (remotePath string, err error)
- func Run(ctx context.Context, client *ssh.Client, log logrus.FieldLogger, cmd string, ...) error
- func RunAndParse(ctx context.Context, client *ssh.Client, log logrus.FieldLogger, cmd string, ...) (err error)
- func RunCommandWithOutput(session *ssh.Session, log logrus.FieldLogger, command string, w io.Writer) (err error)
- func RunCommands(ctx context.Context, client *ssh.Client, log logrus.FieldLogger, ...) error
- func RunScript(ctx context.Context, client *ssh.Client, log logrus.FieldLogger, ...) error
- func TestFile(ctx context.Context, client *ssh.Client, log logrus.FieldLogger, ...) error
- func TransferFile(ctx context.Context, client *ssh.Client, log logrus.FieldLogger, ...) (path string, err error)
- func WaitForFile(ctx context.Context, client *ssh.Client, log logrus.FieldLogger, ...) error
- func WaitTimeSync(ctx context.Context, nodes []SshNode) error
- type Cmd
- type ExitStatusError
- type OutputParseFn
- type SshNode
Constants ¶
const ( // TestRegularFile file exists and is a regular file TestRegularFile = "-f" // TestDir file exists and is a directory TestDir = "-d" )
const (
SUDO = true
)
Variables ¶
This section is empty.
Functions ¶
func CheckTimeSync ¶
CheckTimeSync verifies current time is in sync across nodes
func Client ¶
Client creates a new SSH client specified by addr and user. keyInput defines the SSH key to use for authentication. Returns a SSH client
func IsExitMissingError ¶
func MakePrivateKeySignerFromFile ¶
MakePrivateKeySignerFromFile creates a singer from the specified path
func MakePrivateKeySignerFromReader ¶
MakePrivateKeySignerFromReader creates a singer from the specified reader
func ParseDiscard ¶
func PipeCommand ¶
func PipeCommand(ctx context.Context, client *ssh.Client, log logrus.FieldLogger, cmd, dst string) error
PipeCommand will run a remote command and store as local file
func PutFile ¶
func PutFile(ctx context.Context, client *ssh.Client, log logrus.FieldLogger, srcPath, dstDir string) (remotePath string, err error)
PutFile transfers local file to remote host directory
func Run ¶
func Run(ctx context.Context, client *ssh.Client, log logrus.FieldLogger, cmd string, env map[string]string) error
Run is a simple method to run external program and don't care about its output or exit status
func RunAndParse ¶
func RunAndParse( ctx context.Context, client *ssh.Client, log logrus.FieldLogger, cmd string, env map[string]string, parse OutputParseFn, ) (err error)
RunAndParse runs remote SSH command cmd with environment variables set with env. parse if set, will be provided the reader that consumes stdout of the command. Returns *ssh.ExitError if the command has completed with a non-0 exit code, *ssh.ExitMissingError if the other side has terminated the session without providing the exit code and nil for no errors
func RunCommandWithOutput ¶
func RunCommandWithOutput(session *ssh.Session, log logrus.FieldLogger, command string, w io.Writer) (err error)
RunCommandWithOutput executes the specified command in given session and streams session's Stderr/Stdout into w. The function takes ownership of session and will destroy it upon completion of the command
func RunCommands ¶
func RunCommands(ctx context.Context, client *ssh.Client, log logrus.FieldLogger, commands []Cmd) error
RunCommands executes commands sequentially
func RunScript ¶
func RunScript(ctx context.Context, client *ssh.Client, log logrus.FieldLogger, scriptPath string, sudo bool) error
RunScript will run a .sh script on remote host if script should not be executed it should have internal flag files and terminate
func TestFile ¶
func TestFile(ctx context.Context, client *ssh.Client, log logrus.FieldLogger, path, test string) error
TestFile tests remote file using `test` command. It returns trace.NotFound in case test fails, nil is test passes, and unspecified error otherwise
func TransferFile ¶
func TransferFile(ctx context.Context, client *ssh.Client, log logrus.FieldLogger, fileUrl, dstDir string, env map[string]string) (path string, err error)
TransferFile takes file URL which may be S3 or HTTP or local file and transfers it to remote the machine fileUrl - file to download, could be S3:// or http(s)://
func WaitForFile ¶
func WaitForFile(ctx context.Context, client *ssh.Client, log logrus.FieldLogger, path, test string) error
WaitForFile waits for a test to become true against a remote file (or context to expire)
Types ¶
type Cmd ¶
type Cmd struct { // Command is what is passed to remote shell Command string // Env are any environment variables to be set // Note that environment vars must be explicitly enabled in /etc/ssh/sshd.conf `AcceptEnv` directive Env map[string]string }
Cmd defines command to execute on remote host
type ExitStatusError ¶
type ExitStatusError interface { // ExitStatus reports the exist status of an operation ExitStatus() int }
ExitStatusError describes the class of errors that report exit status
type OutputParseFn ¶
func ParseAsString ¶
func ParseAsString(out *string) OutputParseFn