Documentation
¶
Overview ¶
Package sshx is the single SSH connection path used by the rest of kay. It dials with public-key auth, verifies host keys with trust-on-first-use, and exposes one-shot command execution and an interactive shell.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotReady = errors.New("ssh connection not ready")
ErrNotReady is returned by Managed.Run when the underlying connection is not currently established (it is connecting, backing off, or reconnecting).
var ErrPoolClosed = errors.New("ssh pool closed")
ErrPoolClosed is returned when an operation is attempted after Close.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps an *ssh.Client with the helpers kay needs.
func Dial ¶
func Dial(opts DialOptions) (*Client, error)
Dial establishes an authenticated connection.
func (*Client) Close ¶
Close terminates the connection and stops the keepalive goroutine. It is safe to call more than once. The done channel is never reassigned after Dial, so the keepalive goroutine reads it without racing Close.
func (*Client) Ping ¶ added in v0.2.0
Ping sends an OpenSSH keepalive global request and reports whether the peer answered. It is deadline-guarded: a black-hole peer that never replies can't wedge the caller (golang/go#21478), so it is safe to call from a health probe.
type ConnState ¶ added in v0.2.0
type ConnState int
ConnState is the lifecycle state of a Managed connection.
type DialOptions ¶
type DialOptions struct {
Addr string // host:port
User string
Signer ssh.Signer
Password string // optional; enables password auth (e.g. assisted install)
KnownHostsPath string
Insecure bool // skip host key verification (dangerous)
Timeout time.Duration
}
DialOptions configures a connection.
type Managed ¶ added in v0.2.0
type Managed struct {
// contains filtered or unexported fields
}
Managed is a self-healing connection to one host: it keeps a single live connection, reconnecting with exponential backoff and jitter after a failure, and hands the live connection to callers. All command execution reuses the same transport, so only the first dial pays the handshake cost.
func (*Managed) Client ¶ added in v0.2.0
Client returns the live *Client for direct reuse (e.g. drilling into a host's dashboard without a second handshake), or nil when not currently ready.
func (*Managed) Close ¶ added in v0.2.0
func (m *Managed) Close()
Close stops maintaining the connection and tears down the live transport.
func (*Managed) Run ¶ added in v0.2.0
Run executes a command on the live connection, reusing the transport. It returns ErrNotReady immediately (without blocking) when no connection is currently established, so a caller polling many hosts never stalls on one that is down. A transport-level failure schedules a reconnect.
type Pool ¶ added in v0.2.0
type Pool struct {
// contains filtered or unexported fields
}
Pool owns a set of Managed connections and the dial concurrency limit shared across them. Capping concurrent dials keeps a cold start of many hosts from tripping a server's sshd MaxStartups throttle or exhausting local sockets.
func NewPool ¶ added in v0.2.0
NewPool returns a pool that permits at most maxDials concurrent dials across all its connections. A non-positive maxDials defaults to 16.