sshconn

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 18, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn interface {
	NewSFTP(ctx context.Context) (SFTPClient, error)
	NewSession(ctx context.Context) (Session, error)
	SendKeepAlive(ctx context.Context) error
	Close() error
}

Conn describes the operations required from an SSH connection.

type DialConfig

type DialConfig struct {
	// Host is passed to ssh_config resolution as the target. It may be a
	// literal hostname or IP, or a Host alias defined in ~/.ssh/config.
	Host string
	// User, if non-empty, overrides the user resolved from ssh_config.
	User string
	// Port, if non-zero, overrides the port resolved from ssh_config.
	Port int
	// Timeout is the TCP connect timeout used when ssh_config's
	// ConnectTimeout is unset. Zero means no timeout.
	Timeout time.Duration
}

DialConfig specifies the minimum identification parameters for a machineproxy SSH connection. Everything else (identity file, known hosts, algorithm lists, keepalives, etc.) is resolved from the user's ssh_config.

type Dialer

type Dialer struct {
	// Dial establishes a fresh SSH connection to the remote.
	Dial func(ctx context.Context) (Conn, error)
	// Addr is the resolved "host:port" address of the remote after
	// ssh_config Hostname/Port substitutions.
	Addr string
	// KeepAliveInterval is ServerAliveInterval from ssh_config, or zero
	// when the user did not configure keepalives.
	KeepAliveInterval time.Duration
}

Dialer carries a dial closure and metadata derived from the resolved ssh_config options. NewDialer resolves the configuration once so every reconnect attempt reuses the same ClientConfig.

func NewDialer

func NewDialer(cfg DialConfig) (*Dialer, error)

NewDialer resolves ssh_config for cfg.Host and returns a Dialer ready to be handed to a Manager. Identity keys, known_hosts, crypto preferences and timeouts all come from the library's ssh_config resolution.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

func NewManager

func NewManager(opts Options) *Manager

func (*Manager) Close

func (m *Manager) Close() error

func (*Manager) CurrentConn

func (m *Manager) CurrentConn() Conn

func (*Manager) IsConnected

func (m *Manager) IsConnected() bool

func (*Manager) LastErr

func (m *Manager) LastErr() error

LastErr returns the most recent connection error, or nil if the last attempt succeeded. Useful for surfacing why the manager is not connected.

func (*Manager) NewSession

func (m *Manager) NewSession(ctx context.Context) (Session, error)

NewSession creates an SSH session from the current connection. Returns an error if the connection is not established.

func (*Manager) SFTP

func (m *Manager) SFTP() SFTPClient

func (*Manager) Start

func (m *Manager) Start(ctx context.Context) error

type Options

type Options struct {
	Dial              func(ctx context.Context) (Conn, error)
	ReconnectInterval time.Duration
	KeepAliveInterval time.Duration
	Log               *slog.Logger
}

type SFTPClient

type SFTPClient interface {
	Close() error
}

SFTPClient is a minimal close-able interface used by the connection manager. Concrete code can wrap *sftp.Client.

type Session

type Session interface {
	StdinPipe() (io.WriteCloser, error)
	StdoutPipe() (io.Reader, error)
	StderrPipe() (io.Reader, error)
	Setenv(name, value string) error
	Start(cmd string) error
	Wait() error
	Close() error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL