Documentation ¶
Index ¶
- Constants
- func DefaultConnectBackoff() retry.Backoff
- func DefaultSSHConfig(privateKey []byte) (*ssh.ClientConfig, error)
- func DefaultSSHConfigFromSigners(signers ...ssh.Signer) (*ssh.ClientConfig, error)
- func GeneratePrivateKey() ([]byte, error)
- func IsConnectionError(err error) bool
- type Client
- func (c *Client) Close()
- func (c *Client) LocalAddr() net.Addr
- func (c *Client) NewSFTPClient() (*sftp.Client, error)
- func (c *Client) Reconnect(ctx context.Context) error
- func (c *Client) ReconnectWithBackoff(ctx context.Context, backoff retry.Backoff) error
- func (c *Client) RegisterDisconnectListener(ch chan struct{})
- func (c *Client) Run(ctx context.Context, command []string, stdout io.Writer, stderr io.Writer) error
- func (c *Client) Start(ctx context.Context, command []string, stdout io.Writer, stderr io.Writer) (*Session, error)
- type Conn
- func (c *Conn) Close()
- func (c *Conn) NewSFTPClient() (*sftp.Client, error)
- func (c *Conn) RegisterDisconnectListener(ch chan struct{})
- func (c *Conn) Run(ctx context.Context, command []string, stdout io.Writer, stderr io.Writer) error
- func (c *Conn) Start(ctx context.Context, command []string, stdout io.Writer, stderr io.Writer) (*Session, error)
- type ConnectionError
- type ConstantAddrResolver
- type Resolver
- type Session
Constants ¶
const ( // Default SSH server port. SSHPort = 22 // Default RSA key size. RSAKeySize = 2048 )
Variables ¶
This section is empty.
Functions ¶
func DefaultConnectBackoff ¶
DefaultConnectBackoff is a sensible default for SSH clients.
func DefaultSSHConfig ¶
func DefaultSSHConfig(privateKey []byte) (*ssh.ClientConfig, error)
DefaultSSHConfig returns a basic SSH client configuration.
func DefaultSSHConfigFromSigners ¶
func DefaultSSHConfigFromSigners(signers ...ssh.Signer) (*ssh.ClientConfig, error)
DefaultSSHConfigFromSigners returns a basic SSH client configuration.
func GeneratePrivateKey ¶
GeneratePrivateKey generates a private SSH key.
func IsConnectionError ¶
IsConnectionError determines whether the given error is a ConnectionError. This is a common check that we include in sshutil to save callers a line of code.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClient ¶
func NewClient( ctx context.Context, resolver Resolver, config *ssh.ClientConfig, connectBackoff retry.Backoff, ) (*Client, error)
NewClient creates a new ssh client to the address.
func (*Client) LocalAddr ¶
LocalAddr returns the local address being used by the underlying ssh.Client.
func (*Client) NewSFTPClient ¶
NewSFTPClient returns an SFTP client that uses the currently underlying ssh.Client. The SFTP client will become unresponsive if the ssh connection is closed and/or refreshed.
func (*Client) Reconnect ¶
Reconnect will disconnect and then reconnect the client, using the client's `connectBackoff` to determine the retry strategy.
func (*Client) ReconnectWithBackoff ¶
ReconnectWithBackoff will disconnect the client from the server if connected, then reconnect to the server, with a retry strategy based on the given backoff.
func (*Client) RegisterDisconnectListener ¶
func (c *Client) RegisterDisconnectListener(ch chan struct{})
RegisterDisconnectListener adds a waiter that gets notified when the ssh client is disconnected.
type Conn ¶
Conn is a wrapper around ssh that supports keepalive and auto-reconnection.
func (*Conn) NewSFTPClient ¶
NewSFTPClient returns an SFTP client that uses the currently underlying ssh.Client. The SFTP client will become unresponsive if the ssh connection is closed and/or refreshed.
func (*Conn) RegisterDisconnectListener ¶
func (c *Conn) RegisterDisconnectListener(ch chan struct{})
RegisterDisconnectListener adds a waiter that gets notified when the ssh client is disconnected.
type ConnectionError ¶
type ConnectionError struct {
Err error
}
ConnectionError is an all-purpose error indicating that a client has become unresponsive.
func (ConnectionError) Error ¶
func (e ConnectionError) Error() string
func (ConnectionError) Unwrap ¶
func (e ConnectionError) Unwrap() error
type ConstantAddrResolver ¶
ConstantAddrResolver allows a constant address to be resolved to itself.
type Resolver ¶
Resolver produces a `net.Addr` for the sshutil connections. It abstracts over how the address is produced in order to support non-DNS based names, such as how Fuchsia devices can be discovered through a MAC-address based name.