executor

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package executor runs commands locally or over SSH.

Commands are always described as argv slices, never as shell strings. The local executor passes argv straight to exec.Command (no shell involved). The SSH executor must produce a string for the remote shell, so every element is single-quoted by ShellQuote before joining — the remote shell therefore sees each argv element as one literal word, and metacharacters in agent-supplied arguments cannot start a new command.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func QuoteArgv

func QuoteArgv(argv []string) string

QuoteArgv renders argv as a single shell-safe command string.

func ShellQuote

func ShellQuote(s string) string

ShellQuote wraps s in single quotes for POSIX shells, escaping embedded single quotes. The result is always exactly one shell word.

Types

type Executor

type Executor interface {
	Run(ctx context.Context, argv []string) (Result, error)
	Close() error
	Name() string
}

Executor runs an argv on some machine.

type Local

type Local struct{}

Local runs commands on the machine opsgate is running on.

func (Local) Close

func (Local) Close() error

func (Local) Name

func (Local) Name() string

func (Local) Run

func (Local) Run(ctx context.Context, argv []string) (Result, error)

type Result

type Result struct {
	Stdout   string
	Stderr   string
	ExitCode int
	Duration time.Duration
}

Result is the outcome of one command.

type SSH

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

SSH runs commands on a remote host over SSH.

func DialSSH

func DialSSH(name, addr, user, keyPath string, port int, timeout time.Duration) (*SSH, error)

DialSSH connects to addr. It authenticates with keyPath when given, otherwise with ssh-agent. Host keys are verified against known_hosts.

func (*SSH) Close

func (s *SSH) Close() error

func (*SSH) Name

func (s *SSH) Name() string

func (*SSH) Run

func (s *SSH) Run(ctx context.Context, argv []string) (Result, error)

Jump to

Keyboard shortcuts

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