ssh

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2019 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package ssh implements various SSH commands.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Logger  *zap.Logger
	KeyPath string

	PublicIP      string
	PublicDNSName string

	// UserName is the user name to use for log-in.
	// "ec2-user" for Amazon Linux 2
	// "ubuntu" for ubuntu
	UserName string

	Envs map[string]string
}

Config defines SSH configuration.

type Op

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

Op represents a SSH operation.

type OpOption

type OpOption func(*Op)

OpOption configures archiver operations.

func WithEnv

func WithEnv(k, v string) OpOption

WithEnv adds an environment variable that will be applied to any command executed by Shell or Run. It overwrites the ones set by "*ssh.Session.Setenv".

func WithRetry

func WithRetry(retries int, interval time.Duration) OpOption

WithRetry automatically retries the command on closed TCP connection error. (e.g. retry immutable operation). WithRetry(-1) to retry forever until success.

func WithTimeout

func WithTimeout(timeout time.Duration) OpOption

WithTimeout configures timeout for command run.

func WithVerbose

func WithVerbose(b bool) OpOption

WithVerbose configures verbose level in SSH operations.

type SSH

type SSH interface {
	// Connect connects to a remote server creating a new client session.
	// "Close" must be called after use.
	Connect() error
	// Close closes the session and connection to a remote server.
	Close()
	// Run runs the command and returns the output.
	Run(cmd string, opts ...OpOption) (out []byte, err error)
	// Send sends a file to the remote host using SCP protocol.
	Send(localPath, remotePath string, opts ...OpOption) (out []byte, err error)
	// Download downloads a file from the remote host using SCP protocol.
	Download(remotePath, localPath string, opts ...OpOption) (out []byte, err error)
}

SSH defines SSH operations.

func New

func New(cfg Config) (s SSH, err error)

New returns a new SSH.

Jump to

Keyboard shortcuts

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