ssh

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package ssh provides SSH connectivity utilities for remote server automation. It wraps github.com/sfreiberg/simplessh with a simplified API for playbook-style operations where you connect, run commands, and disconnect.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrivateKeyPath

func PrivateKeyPath(sshKey string) string

PrivateKeyPath constructs the absolute path to an SSH private key file. It combines the current user's home directory with the .ssh directory and the provided key filename.

func Run added in v0.9.0

func Run(cfg types.NodeConfig, cmd types.Command) (string, error)

Run connects to a node using NodeConfig and executes a command. It extracts SSH connection settings (SSHHost, SSHPort, SSHLogin, SSHKey) from the config and runs the command, returning the output.

If cfg.BecomeUser is set, the command is wrapped with sudo -u <user>.

SAFETY: When cfg.IsDryRunMode is true, this function will NOT execute any commands on the server. Instead, it logs the command and returns "[dry-run]" as the output. This ensures no accidental changes in dry-run mode.

IMPORTANT: The callers must not rely on the safety net of this function. They should handle the dry-run mode themselves before calling this function. This is just a final safety net, as a last resort for implementation mistakes.

func SetRunFunc added in v0.10.0

func SetRunFunc(fn func(types.NodeConfig, types.Command) (string, error))

SetRunFunc sets a custom function for executing SSH commands. This is intended for testing purposes only. Call with nil to restore the default behavior.

Types

type Client

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

Client wraps an SSH connection with convenient methods for running commands.

func NewClient

func NewClient(host, port, user, key string) *Client

NewClient creates a new SSH client configuration. The host parameter should be just the hostname or IP (e.g., "db3.sinevia.com"). The port parameter is the SSH port (e.g., "22" or "40022"). The key parameter is just the filename (e.g., "2024_sinevia.prv"), which gets resolved to ~/.ssh/<key>.

func (*Client) Close

func (c *Client) Close() error

Close closes the SSH connection.

func (*Client) Connect

func (c *Client) Connect() error

Connect establishes the SSH connection. Must be called before Run or Close. Returns an error if the host is empty.

func (*Client) Run

func (c *Client) Run(cmd string) (string, error)

Run executes a command on the remote server. Returns combined stdout/stderr output and any error.

Jump to

Keyboard shortcuts

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