Documentation
¶
Overview ¶
Package exec provides subprocess helpers that keep secrets out of argv.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrEmptyName = errors.New("runwithenv: executable name must not be empty")
ErrEmptyName is returned when an empty executable name is passed to RunWithEnv.
var ErrNilContext = errors.New("runwithenv: context must not be nil")
ErrNilContext is returned when a nil context is passed to RunWithEnv.
Functions ¶
func RunWithEnv ¶
func RunWithEnv(ctx context.Context, extraEnv map[string]string, name string, args ...string) ([]byte, error)
RunWithEnv runs name with args, injecting extraEnv into the subprocess environment. Credentials passed via extraEnv never appear in the process table (argv is the only public part of a process visible to `ps`).
The subprocess inherits the current process environment (os.Environ()) with each key in extraEnv added or overridden. Callers can therefore observe exactly which variables are being injected: they are listed in extraEnv.
Returns combined stdout+stderr and the first error encountered (context cancellation, exec failure, or non-zero exit).
Inputs:
- ctx: cancellation/deadline; non-nil required.
- extraEnv: map of KEY -> VALUE to inject; nil or empty map is valid.
- name: executable name or absolute path; must be non-empty.
- args: arguments passed to name; no credential values should appear here.
Failure modes:
- ctx is nil: returns ErrNilContext immediately (no exec).
- name is empty: returns ErrEmptyName immediately (no exec).
- executable not found: exec.CommandContext returns the error from os/exec.
- non-zero exit: error wraps the combined output for diagnosis.
- context canceled/timed out: error reflects the context state.
Types ¶
This section is empty.