Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrEmptyUsername = errors.New("empty username") ErrEmptyPassword = errors.New("empty password") ErrEmptyAddress = errors.New("empty hostname") ErrInvalidAddress = errors.New("invalid address") ErrInvalidPort = errors.New("invalid port") ErrMissingIPv6Bracket = errors.New("missing closing bracket for IPv6 address") ErrUnexpectedIPv6Suffix = errors.New("unexpected characters after IPv6 address") ErrPortOutOfRange = errors.New("port out of range") )
Host parsing errors returned by ParseHostLine.
Functions ¶
func HostStr ¶ added in v0.0.29
HostStr formats h as "user@addr:port" with the given prefix prepended (use "" for no prefix). The shape is shared by the executor's per-host log lines and cmd/host's tree rendering, so keeping it in one place ensures they stay consistent.
func ToUnixPath ¶ added in v0.0.9
Types ¶
type Host ¶ added in v0.0.9
type Host struct {
// Username is the login username for SSH authentication.
Username string
// Password is the login password for SSH authentication.
Password string
// Address is the hostname or IP of the remote server. For IPv6, it
// keeps the surrounding brackets (e.g. "[2001:db8::1]") so it can
// be used directly with SSH address syntax.
Address string
// Port is the TCP port of the remote server (1-65535).
Port int
}
Host represents a remote server connection with authentication details.
func ParseHostLine ¶ added in v0.0.10
ParseHostLine parses a single host line in the form "user:password@host:port" and returns the resulting Host. Supported shapes for the address part are:
- "host" — defaults port to defaultPort
- "host:port" — host with explicit port
- "[ipv6]" — IPv6 without port, defaults port
- "[ipv6]:port" — IPv6 with explicit port
The rightmost '@' is treated as the user/host separator so that passwords may contain '@'. Returns one of the sentinel errors declared in this package on parse failure.
type HostPool ¶ added in v0.0.9
type HostPool struct {
// contains filtered or unexported fields
}
HostPool manages a cache of Remote connections keyed by Host. It reuses existing connections to avoid redundant SSH/SFTP handshakes.
func NewHostPool ¶ added in v0.0.9
func NewHostPool() *HostPool
NewHostPool creates a new empty HostPool.
type Remote ¶
type Remote struct {
Address string
Port int
Username string
Password string
Logger zerolog.Logger
// contains filtered or unexported fields
}
Remote represents a SSH/SFTP client for remote host operations.
func NewForTesting ¶ added in v0.0.23
NewForTesting builds a *Remote without establishing an SSH connection. Intended for unit tests that need a non-nil Remote to thread through a Module while mocking Execute to never touch the underlying SSH or SFTP clients. Production code must use New.
func (*Remote) Close ¶
Close closes the SSH and SFTP connections. If either close fails, all underlying errors are joined so callers can inspect them with errors.Is / errors.As.
func (*Remote) ExecuteCommand ¶
ExecuteCommand executes a command on the remote host via SSH.
func (*Remote) UploadDir ¶ added in v0.0.10
UploadDir uploads a local directory recursively to remote path with better error handling
func (*Remote) UploadFile ¶
UploadFile uploads a local file to remote path with buffer optimization