Documentation
¶
Overview ¶
Package ssh wraps golang.org/x/crypto/ssh + pkg/sftp into a Client that's narrow enough for the deploy orchestrator to use. It is NOT a general-purpose SSH library — Run / RunStream / Upload / Exists / Stat / MkdirAll / RemoveAll are the only operations.
A Client owns one underlying SSH connection and one SFTP subsystem. It is not safe for concurrent use — use one Client per deploy.
Index ¶
- type Client
- func (c *Client) Close() error
- func (c *Client) Exists(ctx context.Context, remotePath string) (bool, error)
- func (c *Client) MkdirAll(ctx context.Context, remotePath string) error
- func (c *Client) RemoveAll(ctx context.Context, remotePath string) error
- func (c *Client) Run(ctx context.Context, cmd string) (*RunResult, error)
- func (c *Client) RunStream(ctx context.Context, cmd string, stdout, stderr io.Writer) (int, error)
- func (c *Client) SFTP() *sftp.Client
- func (c *Client) Target() Target
- func (c *Client) Upload(ctx context.Context, localPath, remotePath string) error
- type ConnectOpts
- type RunResult
- type Target
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the active SSH + SFTP session.
func (*Client) MkdirAll ¶
MkdirAll creates remotePath and all missing parents. SFTP's stdlib has Mkdir but not MkdirAll — we walk the path and create each segment.
func (*Client) RemoveAll ¶
RemoveAll deletes remotePath recursively. Safe for both files and dirs. Used by the rollback / prune flows. Returns nil if path doesn't exist.
func (*Client) Run ¶
Run executes cmd on the remote and buffers its stdout/stderr until exit. Use RunStream for long-running commands whose output should be visible as it arrives.
A non-zero exit code is NOT returned as an error — the caller decides whether that's failure (e.g. health-check) or expected (e.g. test if a file exists).
func (*Client) RunStream ¶
RunStream executes cmd and copies stdout/stderr to the provided writers as they arrive. The integer return is the remote exit code; the error is non-nil only for transport-level failures (the caller distinguishes non-zero exit from broken transport).
type ConnectOpts ¶
type ConnectOpts struct {
IdentityFile string // path to private key; ~ expanded; required
KnownHostsFile string // path to known_hosts; ~ expanded; default ~/.ssh/known_hosts
Timeout time.Duration // dial timeout; default 15s
KeepAlive time.Duration // SSH keep-alive interval; default 30s
// AllowUnknownHosts skips host-key verification. Default false. Only
// use in tests that target ephemeral containers.
AllowUnknownHosts bool
}
ConnectOpts configures a new Client.
type Target ¶
Target is a parsed "user@host[:port]" SSH destination.
func ParseTarget ¶
ParseTarget accepts "user@host" or "user@host:port". The port defaults to 22. IPv6 addresses in brackets ("user@[::1]:22") are supported.