subprocess

package
v1.20.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2026 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package subprocess provides bounded, redacted subprocess diagnostics.

Index

Constants

View Source
const (
	// MaxCapturedLines and MaxCapturedBytes bound each captured stream.
	MaxCapturedLines = 200
	MaxCapturedBytes = 1 << 20
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

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

Buffer is a bounded, redacting io.Writer for subprocess output.

func NewBuffer

func NewBuffer(redactor *secrets.Redactor) *Buffer

NewBuffer creates a bounded output buffer.

func (*Buffer) String

func (b *Buffer) String() string

func (*Buffer) Truncated

func (b *Buffer) Truncated() bool

func (*Buffer) Write

func (b *Buffer) Write(p []byte) (int, error)

type Options

type Options struct {
	Dir      string
	Env      []string
	Stdin    io.Reader
	Redactor *secrets.Redactor
	// SensitiveValues contains secret values that may appear in argv or in
	// subprocess output but are not represented by a sensitive environment
	// variable. Values are masked before capture and command rendering.
	SensitiveValues []string
	// OperationID links diagnostics to the semantic operation that spawned
	// the command. When empty, Run derives it from ctx.
	OperationID string
}

Options configures a command invocation.

type RedactingWriter

type RedactingWriter struct {
	Next     io.Writer
	Redactor *secrets.Redactor
}

RedactingWriter forwards output after applying redaction. It is useful when a subprocess must stream diagnostics while retaining the same safety policy as captured output.

func (RedactingWriter) Write

func (w RedactingWriter) Write(p []byte) (int, error)

type Result

type Result struct {
	Command        []string
	DisplayCommand string
	OperationID    string
	Stdout         string
	Stderr         string
	ExitCode       int
	Signal         string
	Duration       time.Duration
	Truncated      bool
}

Result contains bounded diagnostic output and execution metadata.

func Run

func Run(ctx context.Context, binary string, args []string, options Options) (Result, error)

Run executes binary with args and captures bounded, redacted output from both streams. The returned error is the original execution error wrapped with the display-safe command; output remains available in Result.

func RunCommand

func RunCommand(cmd *exec.Cmd, redactor *secrets.Redactor) (Result, error)

RunCommand executes an already-configured command with bounded, redacted stdout and stderr capture. Existing command setup such as an explicit environment, working directory, or stdin is preserved.

func (Result) DiagnosticOutput

func (r Result) DiagnosticOutput() string

DiagnosticOutput returns the useful captured tail for a failed command. Output is already bounded and redacted; when capture reached a limit, the suffix is annotated so callers do not present an incomplete diagnostic as the complete command output.

type StreamingRedactingWriter

type StreamingRedactingWriter struct {
	Next     io.Writer
	Redactor *secrets.Redactor
	// contains filtered or unexported fields
}

StreamingRedactingWriter is the chunk-safe variant of RedactingWriter. It retains a short suffix between writes and must be flushed at stream end.

func (*StreamingRedactingWriter) Flush

func (w *StreamingRedactingWriter) Flush() error

Flush forwards the final retained suffix. Callers that stream output should invoke this after the subprocess exits so trailing bytes are not delayed.

func (*StreamingRedactingWriter) Write

func (w *StreamingRedactingWriter) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

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