ssh

package
v0.0.0-...-492d7f2 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2018 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// PasswordAuth represents password based auth.
	PasswordAuth = "password"

	// KeyAuth represents key based authentication.
	KeyAuth = "key"

	// Timeout for connecting to an SSH server.
	Timeout = 60 * time.Second
)

Variables

View Source
var (
	// ErrInvalidUsername is returned when the username is invalid.
	ErrInvalidUsername = errors.New("A valid username must be supplied")
	// ErrInvalidAuth is returned when the username is invalid.
	ErrInvalidAuth = errors.New("Invalid authorization method: missing password or key")
	// ErrSSHInvalidMessageLength is returned when the scp implementation gets an invalid number of messages.
	ErrSSHInvalidMessageLength = errors.New("Invalid message length")
	// ErrTimeout is returned when a timeout occurs waiting for sshd to respond.
	ErrTimeout = errors.New("Timed out waiting for sshd to respond")
	// ErrKeyGeneration is returned when the library fails to generate a key.
	ErrKeyGeneration = errors.New("Unable to generate key")
	// ErrValidation is returned when we fail to validate a key.
	ErrValidation = errors.New("Unable to validate key")
	// ErrPublicKey is returned when gossh fails to parse the public key.
	ErrPublicKey = errors.New("Unable to convert public key")
	// ErrUnableToWriteFile is returned when the library fails to write to a file.
	ErrUnableToWriteFile = errors.New("Unable to write file")
	// ErrNotImplemented is returned when a function is not implemented (typically by the Mock implementation).
	ErrNotImplemented = errors.New("Operation not implemented")
)

Functions

This section is empty.

Types

type Client

type Client interface {
	Connect() error
	Disconnect()
	Download(src io.WriteCloser, dst string) error
	Run(command string, stdout io.Writer, stderr io.Writer) error
	Upload(src io.Reader, dst string, mode uint32) error
	Validate() error
	WaitForSSH(maxWait time.Duration) error

	SetSSHPrivateKey(string)
	GetSSHPrivateKey() string
	SetSSHPassword(string)
	GetSSHPassword() string
}

Client represents an interface for abstracting common ssh operations.

type Credentials

type Credentials struct {
	SSHUser       string
	SSHPassword   string
	SSHPrivateKey string
	// contains filtered or unexported fields
}

Credentials supplies SSH credentials.

type KeyPair

type KeyPair struct {
	PrivateKey []byte
	PublicKey  []byte
}

KeyPair represents a Public and Private keypair.

func NewKeyPair

func NewKeyPair() (keyPair *KeyPair, err error)

NewKeyPair generates a new SSH keypair. This will return a private & public key encoded as DER.

func (*KeyPair) Fingerprint

func (kp *KeyPair) Fingerprint() string

Fingerprint calculates the fingerprint of the public key

func (*KeyPair) ReadFromFile

func (kp *KeyPair) ReadFromFile(privateKeyPath string, publicKeyPath string) error

ReadFromFile reads a keypair from files.

func (*KeyPair) WriteToFile

func (kp *KeyPair) WriteToFile(privateKeyPath string, publicKeyPath string) error

WriteToFile writes a keypair to files

type MockSSHClient

type MockSSHClient struct {
	MockConnect    func() error
	MockDisconnect func()
	MockDownload   func(src io.WriteCloser, dst string) error
	MockRun        func(command string, stdout io.Writer, stderr io.Writer) error
	MockUpload     func(src io.Reader, dst string, mode uint32) error
	MockValidate   func() error
	MockWaitForSSH func(maxWait time.Duration) error

	MockSetSSHPrivateKey func(string)
	MockGetSSHPrivateKey func() string
	MockSetSSHPassword   func(string)
	MockGetSSHPassword   func() string
}

MockSSHClient represents a Mock Client wrapper.

func (*MockSSHClient) Connect

func (c *MockSSHClient) Connect() error

Connect calls the mocked connect.

func (*MockSSHClient) Disconnect

func (c *MockSSHClient) Disconnect()

Disconnect calls the mocked disconnect.

func (*MockSSHClient) Download

func (c *MockSSHClient) Download(src io.WriteCloser, dst string) error

Download calls the mocked download.

func (*MockSSHClient) GetSSHPassword

func (c *MockSSHClient) GetSSHPassword() string

GetSSHPassword calls the mocked GetSSHPassword

func (*MockSSHClient) GetSSHPrivateKey

func (c *MockSSHClient) GetSSHPrivateKey() string

GetSSHPrivateKey calls the mocked GetSSHPrivateKey

func (*MockSSHClient) Run

func (c *MockSSHClient) Run(command string, stdout io.Writer, stderr io.Writer) error

Run calls the mocked run

func (*MockSSHClient) SetSSHPassword

func (c *MockSSHClient) SetSSHPassword(s string)

SetSSHPassword calls the mocked SetSSHPassword

func (*MockSSHClient) SetSSHPrivateKey

func (c *MockSSHClient) SetSSHPrivateKey(s string)

SetSSHPrivateKey calls the mocked SetSSHPrivateKey

func (*MockSSHClient) Upload

func (c *MockSSHClient) Upload(src io.Reader, dst string, mode uint32) error

Upload calls the mocked upload

func (*MockSSHClient) Validate

func (c *MockSSHClient) Validate() error

Validate calls the mocked validate.

func (*MockSSHClient) WaitForSSH

func (c *MockSSHClient) WaitForSSH(maxWait time.Duration) error

WaitForSSH calls the mocked WaitForSSH

type Options

type Options struct {
	IPs       []net.IP
	KeepAlive int
	Pty       bool
}

Options provides SSH options like KeepAlive.

type SSHClient

type SSHClient struct {
	Creds   *Credentials
	IP      net.IP
	Port    int
	Options Options
	// contains filtered or unexported fields
}

SSHClient provides details for the SSH connection.

func (*SSHClient) Connect

func (client *SSHClient) Connect() error

Connect connects to a machine using SSH.

func (*SSHClient) Disconnect

func (client *SSHClient) Disconnect()

Disconnect should be called when the ssh client is no longer needed, and state can be cleaned up

func (*SSHClient) Download

func (client *SSHClient) Download(dst io.WriteCloser, remotePath string) error

Download downloads a file via SSH (SCP)

func (*SSHClient) GetSSHPassword

func (client *SSHClient) GetSSHPassword() string

GetSSHPassword gets the SSH password on the clients credentials.

func (*SSHClient) GetSSHPrivateKey

func (client *SSHClient) GetSSHPrivateKey() string

GetSSHPrivateKey gets the private key on the clients credentials.

func (*SSHClient) Run

func (client *SSHClient) Run(command string, stdout io.Writer, stderr io.Writer) error

Run runs a command via SSH.

func (*SSHClient) SetSSHPassword

func (client *SSHClient) SetSSHPassword(s string)

SetSSHPassword sets the SSH password on the clients credentials.

func (*SSHClient) SetSSHPrivateKey

func (client *SSHClient) SetSSHPrivateKey(s string)

SetSSHPrivateKey sets the private key on the clients credentials.

func (*SSHClient) Upload

func (client *SSHClient) Upload(src io.Reader, dst string, mode uint32) error

Upload uploads a new file via SSH (SCP)

func (*SSHClient) Validate

func (client *SSHClient) Validate() error

Validate verifies that SSH connection credentials were properly configured.

func (*SSHClient) WaitForSSH

func (client *SSHClient) WaitForSSH(maxWait time.Duration) error

WaitForSSH will try to connect to an SSH server. If it fails, then it'll sleep for 5 seconds.

Jump to

Keyboard shortcuts

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