ssh

package
v0.0.0-...-b8e8469 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotConnected = errors.New("ssh console node not connected")

ErrNotConnected means a managed node is temporarily disconnected. Write discards input and returns this error until reconnect.

Functions

This section is empty.

Types

type SSHConfig

type SSHConfig struct {
	TerminalType         string        `desc:"Terminal type for SSH PTY requests"`
	TCPKeepAlive         time.Duration `desc:"TCP keepalive interval for SSH connections (0 disables)"`
	ConnectTimeout       time.Duration `desc:"Deadline for the TCP dial and SSH handshake"`
	ReconnectMinInterval time.Duration `flag:"-"`
	ReconnectMaxInterval time.Duration `flag:"-"`
}

SSHConfig configures SSH consoles.

func DefaultSSHConfig

func DefaultSSHConfig() SSHConfig

DefaultSSHConfig returns the default SSH console settings.

func (SSHConfig) Validate

func (c SSHConfig) Validate() error

Validate checks SSH console settings.

type SSHConsole

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

SSHConsole manages one SSH node and persists across connections. Run owns log and client channel writes and reconnects until cancelled.

func (*SSHConsole) Attach

func (c *SSHConsole) Attach(clientID string) chan []byte

Attach registers a buffered client channel.

func (*SSHConsole) Detach

func (c *SSHConsole) Detach(clientID string)

Detach deregisters a client channel. Idempotent.

func (*SSHConsole) ReopenLog

func (c *SSHConsole) ReopenLog()

ReopenLog signals the Run goroutine to reopen the log file (after rotation).

func (*SSHConsole) Run

func (c *SSHConsole) Run(ctx context.Context)

Run connects, broadcasts output, and reconnects until cancelled. The manager controls its lifetime and must not retain a stopped console.

func (*SSHConsole) UpdateCreds

func (c *SSHConsole) UpdateCreds(creds compcredentials.CompCredentials)

UpdateCreds updates stored credentials and forces a reconnect so the new credentials take effect.

func (*SSHConsole) Write

func (c *SSHConsole) Write(p []byte) (int, error)

Write sends data to the SSH session. ErrNotConnected means no input was written during a reconnect.

type SSHConsoleManager

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

SSHConsoleManager manages one console for each SSH node.

func NewSSHConsoleManager

func NewSSHConsoleManager(cfg SSHConfig, keyPath, logsPath string) *SSHConsoleManager

NewSSHConsoleManager creates a manager from validated configuration. keyPath may be empty when all nodes use password authentication. logsPath stores per-node console logs.

func (*SSHConsoleManager) Attach

func (m *SSHConsoleManager) Attach(nodeID, clientID string) (chan []byte, error)

Attach connects a client and fails if the node is unmanaged.

func (*SSHConsoleManager) Detach

func (m *SSHConsoleManager) Detach(nodeID, clientID string)

Detach disconnects a client and ignores unmanaged nodes.

func (*SSHConsoleManager) ReopenLogs

func (m *SSHConsoleManager) ReopenLogs()

ReopenLogs signals all active consoles to reopen their log files after rotation.

func (*SSHConsoleManager) Shutdown

func (m *SSHConsoleManager) Shutdown()

Shutdown stops all consoles and waits for their cleanup.

func (*SSHConsoleManager) UpdateCredentials

func (m *SSHConsoleManager) UpdateCredentials(passwords map[string]compcredentials.CompCredentials)

UpdateCredentials reconnects managed nodes whose credentials changed. UpdateNodes handles membership and never changes authentication. Missing entries leave existing credentials unchanged because reads may be partial, and entries for unmanaged nodes are ignored. An empty password selects key authentication.

func (*SSHConsoleManager) UpdateNodes

func (m *SSHConsoleManager) UpdateNodes(
	ctx context.Context,
	nodes map[string]*nodes.NodeConsoleInfo,
) error

UpdateNodes syncs managed consoles with the complete inventory. It starts new SSH nodes and stops removed or retyped nodes. Connection changes restart a console with its existing credentials, while new nodes wait for UpdateCredentials before connecting. ctx controls console lifetime.

func (*SSHConsoleManager) Wait

func (m *SSHConsoleManager) Wait()

Wait blocks until all Run goroutines exit but does not stop them. Callers cancel their contexts first and then wait for log cleanup.

func (*SSHConsoleManager) Write

func (m *SSHConsoleManager) Write(nodeID string, p []byte) (int, error)

Write sends data to a node and distinguishes unmanaged nodes from temporary disconnections.

Jump to

Keyboard shortcuts

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