sshrunner

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrExecNotFound = errors.New("exec not found")

Functions

func ExitError

func ExitError(argv []string, res *Result) error

ExitError reports a non-zero exit as an error naming the command that failed.

func NewClientConfig

func NewClientConfig(cfg coretypes.SSHConfig, user string, timeout time.Duration) (*ssh.ClientConfig, error)

NewClientConfig builds the ssh client config core uses for every node it drives over SSH.

func NodeInfo

func NodeInfo(ctx context.Context, runner Runner, root string) (*enginetypes.Info, error)

func ParseEndpoint

func ParseEndpoint(endpoint, prefix string) (user, host, addr string, err error)

ParseEndpoint splits <prefix>[user@]host[:port] into its ssh user, host and dial address.

func Quote

func Quote(argv []string) string

Quote renders argv as one shell line, so no argument is ever interpolated.

func Reader

func Reader(sess Session) io.ReadCloser

Reader streams a running command's stdout and closes the session with it.

func Shell

func Shell(body string, args ...string) []string

Shell wraps a script body into an argv whose positional parameters carry args.

Types

type Execs

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

func NewExecs

func NewExecs() *Execs

func (*Execs) Add

func (e *Execs) Add(execID string, sess Session)

func (*Execs) ExitCode

func (e *Execs) ExitCode(execID string) (int, error)

func (*Execs) Resize

func (e *Execs) Resize(execID string, height, width uint) error

type FileInfo

type FileInfo struct {
	UID  int
	GID  int
	Mode os.FileMode
}

FileInfo is the ownership and mode of a node-side file.

type Files

type Files interface {
	Open(path string) (io.ReadCloser, error)
	Create(path string) (io.WriteCloser, error)
	MkdirAll(path string) error
	Stat(path string) (*FileInfo, error)
	Chown(path string, uid, gid int) error
	Chmod(path string, mode os.FileMode) error
	Close() error
}

Files is sftp access to the node's filesystem.

type Result

type Result struct {
	Stdout string
	Stderr string
	Code   int
}

Result is what a finished command left behind.

func Call

func Call(ctx context.Context, runner Runner, argv ...string) (*Result, error)

Call runs argv on the node; a non-zero exit is reported in the result, not as an error.

func Run

func Run(ctx context.Context, runner Runner, argv ...string) (*Result, error)

Run runs argv on the node and reports a non-zero exit as an error.

type Runner

type Runner interface {
	Run(ctx context.Context, line string, stdin io.Reader) (*Result, error)
	Start(ctx context.Context, line string, opts *StartOptions) (Session, error)
	Files(ctx context.Context) (Files, error)
	Dial(ctx context.Context, network, addr string) (net.Conn, error)
	Close() error
}

Runner drives one node over a single SSH connection.

func New

func New(addr string, config *ssh.ClientConfig) Runner

New builds a runner that dials addr on demand and keeps the connection.

type Session

type Session interface {
	Stdin() io.WriteCloser
	Stdout() io.ReadCloser
	Stderr() io.ReadCloser
	Resize(height, width uint) error
	Wait() (int, error)
	Close() error
}

Session is a command running on the node with its streams attached.

type StartOptions

type StartOptions struct {
	Stdin bool
	TTY   bool
}

StartOptions selects the stream shape of a long-running command.

Directories

Path Synopsis
Package sshrunnertest is a scripted runner every engine's tests drive a node with.
Package sshrunnertest is a scripted runner every engine's tests drive a node with.

Jump to

Keyboard shortcuts

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