ssh

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: MIT Imports: 9 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

Overview

Package ssh provides a thin SSH client and parallel fanout helper for the coolify init mesh-bootstrap commands.

Index

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 implements Runner using the golang.org/x/crypto/ssh library. Keys must be unencrypted PEM files. NOTE: host-key verification is intentionally disabled in v1 (alpha). This is acceptable for a bootstrap tool in controlled environments and should be improved in a future release.

func NewClient

func NewClient(keyPath string, passphrase []byte, timeout time.Duration) (*Client, error)

NewClient loads the private key at keyPath and returns a Client ready to SSH into hosts. If passphrase is non-nil it is used to decrypt the key; pass nil for unencrypted keys.

func (*Client) Run

func (c *Client) Run(ctx context.Context, host, user string, port int, cmd string) (string, string, error)

Run connects to host:port over SSH as user, executes cmd, and returns the combined stdout, stderr, and any error. The connection is closed when the command finishes or ctx is cancelled.

func (*Client) UploadFile

func (c *Client) UploadFile(ctx context.Context, host, user string, port int, localPath, remotePath string, mode os.FileMode) error

UploadFile streams localPath to remotePath on host via a single SSH session. The write is atomic: data lands in <remote>.tmp.$PID first and is renamed on success.

type FileUploader

type FileUploader interface {
	UploadFile(ctx context.Context, host, user string, port int, localPath, remotePath string, mode os.FileMode) error
}

FileUploader streams a local file to a remote path via a single SSH session. Kept separate from Runner so existing Runner mocks stay valid.

type Runner

type Runner interface {
	Run(ctx context.Context, host, user string, port int, cmd string) (stdout, stderr string, err error)
}

Runner executes a shell command on a remote host and returns its stdout, stderr, and exit error. It is an interface so tests can inject a fake implementation without opening real SSH connections.

type ServerResult

type ServerResult[T any] struct {
	Host   string
	Result T
	Err    error
}

ServerResult holds the return value (or error) from running a function against a single server.

func ForEachServer

func ForEachServer[T any](
	ctx context.Context,
	hosts []string,
	concurrency int,
	fn func(ctx context.Context, host string) (T, error),
) []ServerResult[T]

ForEachServer runs fn concurrently on every host, honouring the concurrency limit. It always returns a result for every host (even on error) and never returns early — callers inspect each ServerResult.Err.

Jump to

Keyboard shortcuts

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