ssh

package
v0.9.9 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2018 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package ssh allows to manage SSH connections and send commands through them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckPrivateSshConnection

func CheckPrivateSshConnection(t *testing.T, publicHost Host, privateHost Host, command string) string

CheckPrivateSshConnection attempts to connect to privateHost (which is not addressable from the Internet) via a separate publicHost (which is addressable from the Internet) and then executes "command" on privateHost and returns its output. It is useful for checking that it's possible to SSH from a Bastion Host to a private instance.

func CheckPrivateSshConnectionE

func CheckPrivateSshConnectionE(t *testing.T, publicHost Host, privateHost Host, command string) (string, error)

CheckPrivateSshConnectionE attempts to connect to privateHost (which is not addressable from the Internet) via a separate publicHost (which is addressable from the Internet) and then executes "command" on privateHost and returns its output. It is useful for checking that it's possible to SSH from a Bastion Host to a private instance.

func CheckSshCommand

func CheckSshCommand(t *testing.T, host Host, command string) string

CheckSshCommand checks that you can connect via SSH to the given host and run the given command. Returns the stdout/stderr.

func CheckSshCommandE

func CheckSshCommandE(t *testing.T, host Host, command string) (string, error)

CheckSshCommandE checks that you can connect via SSH to the given host and run the given command. Returns the stdout/stderr.

func CheckSshConnection

func CheckSshConnection(t *testing.T, host Host)

CheckSshConnection checks that you can connect via SSH to the given host and fail the test if the connection fails.

func CheckSshConnectionE

func CheckSshConnectionE(t *testing.T, host Host) error

CheckSshConnectionE checks that you can connect via SSH to the given host and return an error if the connection fails.

func Close

func Close(t *testing.T, closeable Closeable, ignoreErrors ...string)

Close closes a Closeable.

func NoOpHostKeyCallback

func NoOpHostKeyCallback(hostname string, remote net.Addr, key ssh.PublicKey) error

NoOpHostKeyCallback is an ssh.HostKeyCallback that does nothing. Only use this when you're sure you don't want to check the host key at all (e.g., only for testing and non-production use cases).

func ScpFileTo added in v0.9.7

func ScpFileTo(t *testing.T, host Host, mode os.FileMode, remotePath, contents string)

ScpFileToE uploads the contents using SCP to the given host and fails the test if the connection fails.

func ScpFileToE added in v0.9.7

func ScpFileToE(t *testing.T, host Host, mode os.FileMode, remotePath, contents string) error

ScpFileToE uploads the contents using SCP to the given host and return an error if the process fails.

Types

type Closeable

type Closeable interface {
	Close() error
}

Closeable can be closed.

type Host

type Host struct {
	Hostname    string
	SshUserName string
	SshKeyPair  *KeyPair
}

Host is a host on AWS.

type JumpHostSession

type JumpHostSession struct {
	JumpHostClient        *ssh.Client
	HostVirtualConnection net.Conn
	HostConnection        ssh.Conn
}

JumpHostSession is a session with a jump host.

func (*JumpHostSession) Cleanup

func (jumpHost *JumpHostSession) Cleanup(t *testing.T)

Cleanup cleans the jump host session up.

type KeyPair

type KeyPair struct {
	PublicKey  string
	PrivateKey string
}

KeyPair is a public and private key pair that can be used for SSH access.

func GenerateRSAKeyPair

func GenerateRSAKeyPair(t *testing.T, keySize int) *KeyPair

GenerateRSAKeyPair generates an RSA Keypair and return the public and private keys.

func GenerateRSAKeyPairE

func GenerateRSAKeyPairE(t *testing.T, keySize int) (*KeyPair, error)

GenerateRSAKeyPairE generates an RSA Keypair and return the public and private keys.

type SshConnectionOptions

type SshConnectionOptions struct {
	Username    string
	Address     string
	Port        int
	AuthMethods []ssh.AuthMethod
	Command     string
	JumpHost    *SshConnectionOptions
}

SshConnectionOptions are the options for an SSH connection.

func (*SshConnectionOptions) ConnectionString

func (options *SshConnectionOptions) ConnectionString() string

ConnectionString returns the connection string for an SSH connection.

type SshSession

type SshSession struct {
	Options  *SshConnectionOptions
	Client   *ssh.Client
	Session  *ssh.Session
	JumpHost *JumpHostSession
	Input    *func(io.WriteCloser)
}

SshSession is a container object for all resources created by an SSH session. The reason we need this is so that we can do a single defer in a top-level method that calls the Cleanup method to go through and ensure all of these resources are released and cleaned up.

func (*SshSession) Cleanup

func (sshSession *SshSession) Cleanup(t *testing.T)

Cleanup cleans up an existing SSH session.

Jump to

Keyboard shortcuts

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