Documentation
¶
Overview ¶
Package ssh allows to manage SSH connections and send commands through them.
Index ¶
- Variables
- func CheckPrivateSSHConnectionContext(t testing.TestingT, ctx context.Context, publicHost *Host, privateHost *Host, ...) string
- func CheckPrivateSSHConnectionContextE(t testing.TestingT, ctx context.Context, publicHost *Host, privateHost *Host, ...) (string, error)
- func CheckPrivateSshConnection(t testing.TestingT, publicHost Host, privateHost Host, command string) stringdeprecated
- func CheckPrivateSshConnectionE(t testing.TestingT, publicHost Host, privateHost Host, command string) (string, error)deprecated
- func CheckSSHCommandContext(t testing.TestingT, ctx context.Context, host *Host, command string) string
- func CheckSSHCommandContextE(t testing.TestingT, ctx context.Context, host *Host, command string) (string, error)
- func CheckSSHCommandWithRetryContext(t testing.TestingT, ctx context.Context, host *Host, command string, ...) string
- func CheckSSHCommandWithRetryContextE(t testing.TestingT, ctx context.Context, host *Host, command string, ...) (string, error)
- func CheckSSHConnectionContext(t testing.TestingT, ctx context.Context, host *Host)
- func CheckSSHConnectionContextE(t testing.TestingT, ctx context.Context, host *Host) error
- func CheckSSHConnectionWithRetryContext(t testing.TestingT, ctx context.Context, host *Host, retries int, ...)
- func CheckSSHConnectionWithRetryContextE(t testing.TestingT, ctx context.Context, host *Host, retries int, ...) error
- func CheckSshCommand(t testing.TestingT, host Host, command string) stringdeprecated
- func CheckSshCommandE(t testing.TestingT, host Host, command string) (string, error)deprecated
- func CheckSshCommandWithRetry(t testing.TestingT, host Host, command string, retries int, ...) stringdeprecated
- func CheckSshCommandWithRetryE(t testing.TestingT, host Host, command string, retries int, ...) (string, error)deprecated
- func CheckSshConnection(t testing.TestingT, host Host)deprecated
- func CheckSshConnectionE(t testing.TestingT, host Host) errordeprecated
- func CheckSshConnectionWithRetry(t testing.TestingT, host Host, retries int, sleepBetweenRetries time.Duration, ...)deprecated
- func CheckSshConnectionWithRetryE(t testing.TestingT, host Host, retries int, sleepBetweenRetries time.Duration, ...) errordeprecated
- func Close(t testing.TestingT, closeable Closeable, ignoreErrors ...string)
- func FetchContentsOfFile(t testing.TestingT, host Host, useSudo bool, filePath string) stringdeprecated
- func FetchContentsOfFileContext(t testing.TestingT, ctx context.Context, host *Host, useSudo bool, ...) string
- func FetchContentsOfFileContextE(t testing.TestingT, ctx context.Context, host *Host, useSudo bool, ...) (string, error)
- func FetchContentsOfFileE(t testing.TestingT, host Host, useSudo bool, filePath string) (string, error)deprecated
- func FetchContentsOfFiles(t testing.TestingT, host Host, useSudo bool, filePaths ...string) map[string]stringdeprecated
- func FetchContentsOfFilesContext(t testing.TestingT, ctx context.Context, host *Host, useSudo bool, ...) map[string]string
- func FetchContentsOfFilesContextE(t testing.TestingT, ctx context.Context, host *Host, useSudo bool, ...) (map[string]string, error)
- func FetchContentsOfFilesE(t testing.TestingT, host Host, useSudo bool, filePaths ...string) (map[string]string, error)deprecated
- func NoOpHostKeyCallback(hostname string, remote net.Addr, key ssh.PublicKey) error
- func SCPDirFromContext(t testing.TestingT, ctx context.Context, options *SCPDownloadOptions, ...)
- func SCPDirFromContextE(t testing.TestingT, ctx context.Context, options *SCPDownloadOptions, ...) error
- func SCPFileFromContext(t testing.TestingT, ctx context.Context, host *Host, remotePath string, ...)
- func SCPFileFromContextE(t testing.TestingT, ctx context.Context, host *Host, remotePath string, ...) error
- func SCPFileToContext(t testing.TestingT, ctx context.Context, host *Host, mode os.FileMode, ...)
- func SCPFileToContextE(t testing.TestingT, ctx context.Context, host *Host, mode os.FileMode, ...) error
- func ScpDirFrom(t testing.TestingT, options ScpDownloadOptions, useSudo bool)deprecated
- func ScpDirFromE(t testing.TestingT, options ScpDownloadOptions, useSudo bool) errordeprecated
- func ScpFileFrom(t testing.TestingT, host Host, remotePath string, localDestination *os.File, ...)deprecated
- func ScpFileFromE(t testing.TestingT, host Host, remotePath string, localDestination *os.File, ...) errordeprecated
- func ScpFileTo(t testing.TestingT, host Host, mode os.FileMode, remotePath, contents string)deprecated
- func ScpFileToE(t testing.TestingT, host Host, mode os.FileMode, remotePath, contents string) errordeprecated
- type Closeable
- type Host
- type JumpHostSession
- type KeyPair
- type SCPDownloadOptions
- type SSHAgent
- func NewSSHAgent(t testing.TestingT, ctx context.Context, socketDir string, socketFile string) (*SSHAgent, error)
- func NewSshAgent(t testing.TestingT, socketDir string, socketFile string) (*SSHAgent, error)deprecated
- func SSHAgentWithKeyPair(t testing.TestingT, ctx context.Context, keyPair *KeyPair) *SSHAgent
- func SSHAgentWithKeyPairE(t testing.TestingT, ctx context.Context, keyPair *KeyPair) (*SSHAgent, error)
- func SSHAgentWithKeyPairs(t testing.TestingT, ctx context.Context, keyPairs []*KeyPair) *SSHAgent
- func SSHAgentWithKeyPairsE(t testing.TestingT, ctx context.Context, keyPairs []*KeyPair) (*SSHAgent, error)
- func SshAgentWithKeyPair(t testing.TestingT, keyPair *KeyPair) *SSHAgentdeprecated
- func SshAgentWithKeyPairE(t testing.TestingT, keyPair *KeyPair) (*SSHAgent, error)deprecated
- func SshAgentWithKeyPairs(t testing.TestingT, keyPairs []*KeyPair) *SSHAgentdeprecated
- func SshAgentWithKeyPairsE(t testing.TestingT, keyPairs []*KeyPair) (*SSHAgent, error)deprecated
- type SSHConnectionOptions
- type SSHSession
- type ScpDownloadOptionsdeprecated
- type SshAgentdeprecated
- type SshConnectionOptionsdeprecated
- type SshSessiondeprecated
Constants ¶
This section is empty.
Variables ¶
var ErrNoAuthMethod = errors.New("no authentication method defined")
ErrNoAuthMethod is returned when no authentication method (key pair, agent, or password) is configured on a Host.
Functions ¶
func CheckPrivateSSHConnectionContext ¶ added in v1.0.0
func CheckPrivateSSHConnectionContext(t testing.TestingT, ctx context.Context, publicHost *Host, privateHost *Host, command string) string
CheckPrivateSSHConnectionContext 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. This will fail the test if the connection fails. The ctx parameter supports cancellation and timeouts.
func CheckPrivateSSHConnectionContextE ¶ added in v1.0.0
func CheckPrivateSSHConnectionContextE(t testing.TestingT, ctx context.Context, publicHost *Host, privateHost *Host, command string) (string, error)
CheckPrivateSSHConnectionContextE 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. The ctx parameter supports cancellation and timeouts.
func CheckPrivateSshConnection
deprecated
func CheckPrivateSshConnection(t testing.TestingT, 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. This will fail the test if the connection fails.
Deprecated: Use CheckPrivateSSHConnectionContext instead.
func CheckPrivateSshConnectionE
deprecated
func CheckPrivateSshConnectionE(t testing.TestingT, 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.
Deprecated: Use CheckPrivateSSHConnectionContextE instead.
func CheckSSHCommandContext ¶ added in v1.0.0
func CheckSSHCommandContext(t testing.TestingT, ctx context.Context, host *Host, command string) string
CheckSSHCommandContext checks that you can connect via SSH to the given host and run the given command. Returns the stdout/stderr. This will fail the test if the connection fails. The ctx parameter supports cancellation and timeouts.
func CheckSSHCommandContextE ¶ added in v1.0.0
func CheckSSHCommandContextE(t testing.TestingT, ctx context.Context, host *Host, command string) (string, error)
CheckSSHCommandContextE checks that you can connect via SSH to the given host and run the given command. Returns the stdout/stderr. The ctx parameter supports cancellation and timeouts.
func CheckSSHCommandWithRetryContext ¶ added in v1.0.0
func CheckSSHCommandWithRetryContext(t testing.TestingT, ctx context.Context, host *Host, command string, retries int, sleepBetweenRetries time.Duration, f ...func(testing.TestingT, context.Context, *Host, string) (string, error)) string
CheckSSHCommandWithRetryContext checks that you can connect via SSH to the given host and run the given command until max retries have been exceeded. Returns the stdout/stderr. This will fail the test if the connection fails. The ctx parameter supports cancellation and timeouts.
func CheckSSHCommandWithRetryContextE ¶ added in v1.0.0
func CheckSSHCommandWithRetryContextE(t testing.TestingT, ctx context.Context, host *Host, command string, retries int, sleepBetweenRetries time.Duration, f ...func(testing.TestingT, context.Context, *Host, string) (string, error)) (string, error)
CheckSSHCommandWithRetryContextE checks that you can connect via SSH to the given host and run the given command until max retries has been exceeded. Returns an error if the command fails after max retries has been exceeded. The ctx parameter supports cancellation and timeouts.
func CheckSSHConnectionContext ¶ added in v1.0.0
CheckSSHConnectionContext checks that you can connect via SSH to the given host. This will fail the test if the connection fails. The ctx parameter supports cancellation and timeouts.
func CheckSSHConnectionContextE ¶ added in v1.0.0
CheckSSHConnectionContextE checks that you can connect via SSH to the given host and returns an error if the connection fails. The ctx parameter supports cancellation and timeouts.
func CheckSSHConnectionWithRetryContext ¶ added in v1.0.0
func CheckSSHConnectionWithRetryContext(t testing.TestingT, ctx context.Context, host *Host, retries int, sleepBetweenRetries time.Duration, f ...func(testing.TestingT, context.Context, *Host) error)
CheckSSHConnectionWithRetryContext attempts to connect via SSH until max retries has been exceeded. This will fail the test if the connection fails. The ctx parameter supports cancellation and timeouts.
func CheckSSHConnectionWithRetryContextE ¶ added in v1.0.0
func CheckSSHConnectionWithRetryContextE(t testing.TestingT, ctx context.Context, host *Host, retries int, sleepBetweenRetries time.Duration, f ...func(testing.TestingT, context.Context, *Host) error) error
CheckSSHConnectionWithRetryContextE attempts to connect via SSH until max retries has been exceeded and returns an error if the connection fails. The ctx parameter supports cancellation and timeouts.
func CheckSshCommand
deprecated
func CheckSshCommandE
deprecated
func CheckSshCommandWithRetry
deprecated
added in
v0.32.20
func CheckSshCommandWithRetry(t testing.TestingT, host Host, command string, retries int, sleepBetweenRetries time.Duration, f ...func(testing.TestingT, Host, string) (string, error)) string
CheckSshCommandWithRetry checks that you can connect via SSH to the given host and run the given command until max retries have been exceeded. Returns the stdout/stderr. This will fail the test if the connection fails.
Deprecated: Use CheckSSHCommandWithRetryContext instead.
func CheckSshCommandWithRetryE
deprecated
added in
v0.32.20
func CheckSshCommandWithRetryE(t testing.TestingT, host Host, command string, retries int, sleepBetweenRetries time.Duration, f ...func(testing.TestingT, Host, string) (string, error)) (string, error)
CheckSshCommandWithRetryE checks that you can connect via SSH to the given host and run the given command until max retries has been exceeded. Returns an error if the command fails after max retries has been exceeded.
Deprecated: Use CheckSSHCommandWithRetryContextE instead.
func CheckSshConnection
deprecated
CheckSshConnection checks that you can connect via SSH to the given host. This will fail the test if the connection fails.
Deprecated: Use CheckSSHConnectionContext instead.
func CheckSshConnectionE
deprecated
CheckSshConnectionE checks that you can connect via SSH to the given host and returns an error if the connection fails.
Deprecated: Use CheckSSHConnectionContextE instead.
func CheckSshConnectionWithRetry
deprecated
added in
v0.32.20
func CheckSshConnectionWithRetry(t testing.TestingT, host Host, retries int, sleepBetweenRetries time.Duration, f ...func(testing.TestingT, Host) error)
CheckSshConnectionWithRetry attempts to connect via SSH until max retries has been exceeded. This will fail the test if the connection fails.
Deprecated: Use CheckSSHConnectionWithRetryContext instead.
func CheckSshConnectionWithRetryE
deprecated
added in
v0.32.20
func CheckSshConnectionWithRetryE(t testing.TestingT, host Host, retries int, sleepBetweenRetries time.Duration, f ...func(testing.TestingT, Host) error) error
CheckSshConnectionWithRetryE attempts to connect via SSH until max retries has been exceeded and returns an error if the connection fails.
Deprecated: Use CheckSSHConnectionWithRetryContextE instead.
func FetchContentsOfFile
deprecated
added in
v0.9.17
FetchContentsOfFile connects to the given host via SSH and fetches the contents of the file at the given filePath. If useSudo is true, then the contents will be retrieved using sudo. Returns the contents of that file. This will fail the test if the connection fails.
Deprecated: Use FetchContentsOfFileContext instead.
func FetchContentsOfFileContext ¶ added in v1.0.0
func FetchContentsOfFileContext(t testing.TestingT, ctx context.Context, host *Host, useSudo bool, filePath string) string
FetchContentsOfFileContext connects to the given host via SSH and fetches the contents of the file at the given filePath. If useSudo is true, then the contents will be retrieved using sudo. Returns the contents of that file. This will fail the test if the connection fails. The ctx parameter supports cancellation and timeouts.
func FetchContentsOfFileContextE ¶ added in v1.0.0
func FetchContentsOfFileContextE(t testing.TestingT, ctx context.Context, host *Host, useSudo bool, filePath string) (string, error)
FetchContentsOfFileContextE connects to the given host via SSH and fetches the contents of the file at the given filePath. If useSudo is true, then the contents will be retrieved using sudo. Returns the contents of that file. The ctx parameter supports cancellation and timeouts.
func FetchContentsOfFileE
deprecated
added in
v0.9.17
func FetchContentsOfFileE(t testing.TestingT, host Host, useSudo bool, filePath string) (string, error)
FetchContentsOfFileE connects to the given host via SSH and fetches the contents of the file at the given filePath. If useSudo is true, then the contents will be retrieved using sudo. Returns the contents of that file.
Deprecated: Use FetchContentsOfFileContextE instead.
func FetchContentsOfFiles
deprecated
added in
v0.9.17
func FetchContentsOfFiles(t testing.TestingT, host Host, useSudo bool, filePaths ...string) map[string]string
FetchContentsOfFiles connects to the given host via SSH and fetches the contents of the files at the given filePaths. If useSudo is true, then the contents will be retrieved using sudo. Returns a map from file path to contents. This will fail the test if the connection fails.
Deprecated: Use FetchContentsOfFilesContext instead.
func FetchContentsOfFilesContext ¶ added in v1.0.0
func FetchContentsOfFilesContext(t testing.TestingT, ctx context.Context, host *Host, useSudo bool, filePaths ...string) map[string]string
FetchContentsOfFilesContext connects to the given host via SSH and fetches the contents of the files at the given filePaths. If useSudo is true, then the contents will be retrieved using sudo. Returns a map from file path to contents. This will fail the test if the connection fails. The ctx parameter supports cancellation and timeouts.
func FetchContentsOfFilesContextE ¶ added in v1.0.0
func FetchContentsOfFilesContextE(t testing.TestingT, ctx context.Context, host *Host, useSudo bool, filePaths ...string) (map[string]string, error)
FetchContentsOfFilesContextE connects to the given host via SSH and fetches the contents of the files at the given filePaths. If useSudo is true, then the contents will be retrieved using sudo. Returns a map from file path to contents. The ctx parameter supports cancellation and timeouts.
func FetchContentsOfFilesE
deprecated
added in
v0.9.17
func FetchContentsOfFilesE(t testing.TestingT, host Host, useSudo bool, filePaths ...string) (map[string]string, error)
FetchContentsOfFilesE connects to the given host via SSH and fetches the contents of the files at the given filePaths. If useSudo is true, then the contents will be retrieved using sudo. Returns a map from file path to contents.
Deprecated: Use FetchContentsOfFilesContextE instead.
func NoOpHostKeyCallback ¶
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 SCPDirFromContext ¶ added in v1.0.0
func SCPDirFromContext(t testing.TestingT, ctx context.Context, options *SCPDownloadOptions, useSudo bool)
SCPDirFromContext downloads all the files from remotePath on the given host using SCP. This will fail the test if the connection fails. The ctx parameter supports cancellation and timeouts.
func SCPDirFromContextE ¶ added in v1.0.0
func SCPDirFromContextE(t testing.TestingT, ctx context.Context, options *SCPDownloadOptions, useSudo bool) error
SCPDirFromContextE downloads all the files from remotePath on the given host using SCP and returns an error if the process fails. Only files within remotePath will be downloaded. This function will not recursively download subdirectories or follow symlinks. The ctx parameter supports cancellation and timeouts.
func SCPFileFromContext ¶ added in v1.0.0
func SCPFileFromContext(t testing.TestingT, ctx context.Context, host *Host, remotePath string, localDestination *os.File, useSudo bool)
SCPFileFromContext downloads the file from remotePath on the given host using SCP. This will fail the test if the connection fails. The ctx parameter supports cancellation and timeouts.
func SCPFileFromContextE ¶ added in v1.0.0
func SCPFileFromContextE(t testing.TestingT, ctx context.Context, host *Host, remotePath string, localDestination *os.File, useSudo bool) error
SCPFileFromContextE downloads the file from remotePath on the given host using SCP and returns an error if the process fails. The ctx parameter supports cancellation and timeouts.
func SCPFileToContext ¶ added in v1.0.0
func SCPFileToContext(t testing.TestingT, ctx context.Context, host *Host, mode os.FileMode, remotePath, contents string)
SCPFileToContext uploads the contents using SCP to the given host. This will fail the test if the connection fails. The ctx parameter supports cancellation and timeouts.
func SCPFileToContextE ¶ added in v1.0.0
func SCPFileToContextE(t testing.TestingT, ctx context.Context, host *Host, mode os.FileMode, remotePath, contents string) error
SCPFileToContextE uploads the contents using SCP to the given host and returns an error if the process fails. The ctx parameter supports cancellation and timeouts.
func ScpDirFrom
deprecated
added in
v0.12.1
func ScpDirFrom(t testing.TestingT, options ScpDownloadOptions, useSudo bool)
ScpDirFrom downloads all the files from remotePath on the given host using SCP. This will fail the test if the connection fails.
Deprecated: Use SCPDirFromContext instead.
func ScpDirFromE
deprecated
added in
v0.12.1
func ScpDirFromE(t testing.TestingT, options ScpDownloadOptions, useSudo bool) error
ScpDirFromE downloads all the files from remotePath on the given host using SCP and returns an error if the process fails. Only files within remotePath will be downloaded. This function will not recursively download subdirectories or follow symlinks.
Deprecated: Use SCPDirFromContextE instead.
func ScpFileFrom
deprecated
added in
v0.12.1
func ScpFileFromE
deprecated
added in
v0.12.1
func ScpFileToE
deprecated
added in
v0.9.7
Types ¶
type Host ¶
type Host struct {
// SshKeyPair is the SSH key pair to use for authentication. Disabled by default.
SshKeyPair *KeyPair //nolint:staticcheck,revive // preserving existing field name
// OverrideSshAgent enables an in-process [SSHAgent] for connections to this host. Disabled by default.
OverrideSshAgent *SSHAgent //nolint:staticcheck,revive // preserving existing field name
// Hostname is the host name or IP address.
Hostname string
// SshUserName is the SSH user name.
SshUserName string //nolint:staticcheck,revive // preserving existing field name
// Password is the plain text password for authentication. Blank by default.
Password string
// CustomPort is the port number to use to connect to the host. Port 22 is used if unset.
CustomPort int
// SshAgent enables authentication using the existing local SSH agent. Disabled by default.
SshAgent bool //nolint:staticcheck,revive // preserving existing field name
}
Host is a remote host. Set one or more authentication methods on the host; the first valid method will be used.
type JumpHostSession ¶
type JumpHostSession struct {
// JumpHostClient is the SSH client for the jump host.
JumpHostClient *ssh.Client
// HostVirtualConnection is the virtual connection to the target host through the jump host.
HostVirtualConnection net.Conn
// HostConnection is the SSH connection to the target host.
HostConnection ssh.Conn
}
JumpHostSession is a session with a jump host used for tunneling SSH connections.
func (*JumpHostSession) Cleanup ¶
func (jumpHost *JumpHostSession) Cleanup(t testing.TestingT)
Cleanup cleans the jump host session up.
type KeyPair ¶
type KeyPair struct {
// PublicKey is the SSH public key in authorized_keys format.
PublicKey string
// PrivateKey is the PEM-encoded SSH private key.
PrivateKey string
}
KeyPair is a public and private key pair that can be used for SSH access.
func GenerateRSAKeyPair ¶
GenerateRSAKeyPair generates an RSA Keypair and return the public and private keys.
type SCPDownloadOptions ¶ added in v1.0.0
type SCPDownloadOptions struct {
// RemoteDir is the directory on the remote machine to copy files from.
RemoteDir string
// LocalDir is the directory on the local machine to copy files to.
LocalDir string
// FileNameFilters are file name patterns to match. May include bash-style wildcards (e.g., *.log).
FileNameFilters []string
// RemoteHost is the connection information for the remote machine.
RemoteHost Host
// MaxFileSizeMB is the maximum file size in megabytes to download. Files larger than this are skipped.
MaxFileSizeMB int
}
SCPDownloadOptions configures the parameters for downloading files from a remote host via SCP.
type SSHAgent ¶ added in v1.0.0
type SSHAgent struct {
// contains filtered or unexported fields
}
SSHAgent is an in-process SSH agent that can be used for SSH authentication in tests.
func NewSSHAgent ¶ added in v1.0.0
func NewSSHAgent(t testing.TestingT, ctx context.Context, socketDir string, socketFile string) (*SSHAgent, error)
NewSSHAgent creates an SSH agent, starts it in the background, and returns control back to the main thread. You should stop the agent to clean up files afterwards by calling defer s.Stop(). The ctx parameter is used when establishing the Unix socket listener.
func NewSshAgent
deprecated
added in
v0.10.1
NewSshAgent creates an SSH agent, starts it in the background, and returns control back to the main thread. You should stop the agent to clean up files afterwards by calling defer s.Stop().
Deprecated: Use NewSSHAgent instead.
func SSHAgentWithKeyPair ¶ added in v1.0.0
SSHAgentWithKeyPair creates and returns an in-memory SSH agent with the given KeyPair already added. You should stop the agent to clean up files afterwards by calling defer sshAgent.Stop(). This will fail the test if there is an error. The ctx parameter is used when establishing the Unix socket listener.
func SSHAgentWithKeyPairE ¶ added in v1.0.0
func SSHAgentWithKeyPairE(t testing.TestingT, ctx context.Context, keyPair *KeyPair) (*SSHAgent, error)
SSHAgentWithKeyPairE creates and returns an in-memory SSH agent with the given KeyPair already added. You should stop the agent to clean up files afterwards by calling defer sshAgent.Stop(). The ctx parameter is used when establishing the Unix socket listener.
func SSHAgentWithKeyPairs ¶ added in v1.0.0
SSHAgentWithKeyPairs creates and returns an in-memory SSH agent with the given KeyPairs already added. You should stop the agent to clean up files afterwards by calling defer sshAgent.Stop(). This will fail the test if there is an error. The ctx parameter is used when establishing the Unix socket listener.
func SSHAgentWithKeyPairsE ¶ added in v1.0.0
func SSHAgentWithKeyPairsE(t testing.TestingT, ctx context.Context, keyPairs []*KeyPair) (*SSHAgent, error)
SSHAgentWithKeyPairsE creates and returns an in-memory SSH agent with the given KeyPairs already added. You should stop the agent to clean up files afterwards by calling defer sshAgent.Stop(). The ctx parameter is used when establishing the Unix socket listener.
func SshAgentWithKeyPair
deprecated
added in
v0.10.1
SshAgentWithKeyPair creates and returns an in-memory SSH agent with the given KeyPair already added. You should stop the agent to clean up files afterwards by calling defer sshAgent.Stop(). This will fail the test if there is an error.
Deprecated: Use SSHAgentWithKeyPair instead.
func SshAgentWithKeyPairE
deprecated
added in
v0.10.1
SshAgentWithKeyPairE creates and returns an in-memory SSH agent with the given KeyPair already added. You should stop the agent to clean up files afterwards by calling defer sshAgent.Stop().
Deprecated: Use SSHAgentWithKeyPairE instead.
func SshAgentWithKeyPairs
deprecated
added in
v0.10.1
SshAgentWithKeyPairs creates and returns an in-memory SSH agent with the given KeyPairs already added. You should stop the agent to clean up files afterwards by calling defer sshAgent.Stop(). This will fail the test if there is an error.
Deprecated: Use SSHAgentWithKeyPairs instead.
func SshAgentWithKeyPairsE
deprecated
added in
v0.10.1
SshAgentWithKeyPairsE creates and returns an in-memory SSH agent with the given KeyPairs already added. You should stop the agent to clean up files afterwards by calling defer sshAgent.Stop().
Deprecated: Use SSHAgentWithKeyPairsE instead.
func (*SSHAgent) Agent ¶ added in v1.0.0
Agent returns the underlying ssh agent.Agent used by this SSHAgent.
func (*SSHAgent) SocketDir ¶ added in v1.0.0
SocketDir returns the path to the directory containing the SSH agent's Unix socket.
func (*SSHAgent) SocketFile ¶ added in v1.0.0
SocketFile returns the path to the SSH agent's Unix socket file.
type SSHConnectionOptions ¶ added in v1.0.0
type SSHConnectionOptions struct {
// JumpHost is the optional jump host connection options for tunneling.
JumpHost *SSHConnectionOptions
// Username is the SSH user name.
Username string
// Address is the host address.
Address string
// Command is the command to run on the remote host.
Command string
// AuthMethods are the SSH authentication methods to use.
AuthMethods []ssh.AuthMethod
// Port is the SSH port number.
Port int
}
SSHConnectionOptions are the options for an SSH connection.
func (*SSHConnectionOptions) ConnectionString ¶ added in v1.0.0
func (options *SSHConnectionOptions) ConnectionString() string
ConnectionString returns the connection string for an SSH connection.
type SSHSession ¶ added in v1.0.0
type SSHSession struct {
// Options are the SSH connection options.
Options *SSHConnectionOptions
// Client is the SSH client.
Client *ssh.Client
// Session is the SSH session.
Session *ssh.Session
// JumpHost is the optional jump host session for tunneling.
JumpHost *JumpHostSession
// Input is an optional function that writes to the session's stdin pipe.
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 ¶ added in v1.0.0
func (sshSession *SSHSession) Cleanup(t testing.TestingT)
Cleanup cleans up an existing SSH session.
type ScpDownloadOptions
deprecated
added in
v0.12.1
type ScpDownloadOptions = SCPDownloadOptions //nolint:staticcheck,revive // preserving deprecated type name
ScpDownloadOptions is a backwards-compatible alias for SCPDownloadOptions.
Deprecated: Use SCPDownloadOptions instead.
type SshConnectionOptions
deprecated
type SshConnectionOptions = SSHConnectionOptions //nolint:staticcheck,revive // preserving deprecated type name
SshConnectionOptions is a backwards-compatible alias for SSHConnectionOptions.
Deprecated: Use SSHConnectionOptions instead.
type SshSession
deprecated
type SshSession = SSHSession //nolint:staticcheck,revive // preserving deprecated type name
SshSession is a backwards-compatible alias for SSHSession.
Deprecated: Use SSHSession instead.