cliconsole

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package cliconsole turns one typed console line into a vetted argv for the platform CLI and runs it as a child process. It is never a shell.

Index

Constants

View Source
const (
	EnvKillSwitch     = "APP_CLI_CONSOLE"
	EnvIdleTimeout    = "APP_CLI_CONSOLE_IDLE_TIMEOUT"
	EnvCommandTimeout = "APP_CLI_CONSOLE_COMMAND_TIMEOUT"
	EnvMaxOutput      = "APP_CLI_CONSOLE_MAX_OUTPUT_BYTES"
	EnvMaxLine        = "APP_CLI_CONSOLE_MAX_LINE_BYTES"
	EnvMaxSession     = "APP_CLI_CONSOLE_MAX_SESSION"
	EnvOpensPerMinute = "APP_CLI_CONSOLE_OPENS_PER_MINUTE"
	EnvBinary         = "APP_CLI_BINARY"
	EnvRunAsUser      = "APP_CLI_CONSOLE_USER"
)

Environment knobs. APP_CLI_CONSOLE=off wins over the Settings switch.

View Source
const (
	MaxLineBytes = 4096
	MaxArgs      = 64
)

Limits on one console line.

View Source
const (
	StreamStdout = "stdout"
	StreamStderr = "stderr"
)

Output streams.

Variables

View Source
var ErrBinaryMissing = errors.New("CLI binary not found")

ErrBinaryMissing means no usable CLI binary was found.

Functions

func Check

func Check(argv []string) (string, error)

Check vets argv against the CLI command tree, the command allowlist and the flag deny rules. It returns the matched command path, for audit.

func DeniedFlags

func DeniedFlags() []string

DeniedFlags returns the refused flag names, sorted, for docs and tests.

func DispatchArgs

func DispatchArgs(argv []string) []string

DispatchArgs is the argv the CLI dispatches on after it removes scope flags.

func Env

func Env(apiURL, token, home, experimental string) []string

Env builds the child's whole environment: nothing inherited from the control plane, only the loopback API address and the session token.

func FlagDenied

func FlagDenied(name string) bool

FlagDenied reports whether the console refuses flag name on every command.

func IsHost

func IsHost(argv []string) bool

IsHost reports whether a parsed line belongs to the in-process host diagnostics.

func IsReject

func IsReject(err error) bool

IsReject reports whether err is a policy refusal rather than a runtime failure.

func KilledByEnv

func KilledByEnv() bool

KilledByEnv reports whether the environment switches the console off.

func LocateBinary

func LocateBinary(binaryName string) (string, error)

LocateBinary finds the CLI: APP_CLI_BINARY, else "<binaryName>-cli" next to the running control plane. Never PATH, so the server's PATH cannot pick it.

func ParseLine

func ParseLine(line string) ([]string, error)

ParseLine splits line into words with POSIX-style quoting and no expansion. Shell syntax is refused rather than passed through, so nothing typed here can look like it chains, redirects or substitutes.

func Redact

func Redact(argv []string, path string) string

Redact renders argv for the audit log with secret-looking values masked. It errs toward masking: an audit row never needs the value itself.

func SanitizeLine

func SanitizeLine(line string, maxBytes int, secrets ...string) string

SanitizeLine makes one line of child output safe for the browser terminal and the audit log: no terminal escapes or control bytes, secrets masked, length capped. secrets are exact values to mask, such as the session token.

Types

type AllowEntry

type AllowEntry struct {
	Path   string
	Reason string
}

AllowEntry is one reviewed command path the console may run.

func Allowlist

func Allowlist() []AllowEntry

Allowlist returns the reviewed command table, for docs and the drift test.

type Command

type Command struct {
	Name        string   `json:"name"`
	Subcommands []string `json:"subcommands"`
}

Command is one top-level CLI command and its direct subcommands.

func Commands

func Commands() []Command

Commands lists what the console accepts, for client-side completion.

type Config

type Config struct {
	IdleTimeout    time.Duration
	CommandTimeout time.Duration
	MaxSession     time.Duration
	MaxOutputBytes int64
	MaxLineBytes   int
	OpensPerMinute int
	RunAsUser      string
}

Config is the console's resolved environment.

func LoadConfig

func LoadConfig() Config

LoadConfig reads the environment, falling back to safe defaults on bad values.

type RejectError

type RejectError struct{ Reason string }

RejectError explains why a line was refused. Its message is safe to show the operator.

func (*RejectError) Error

func (e *RejectError) Error() string

type Result

type Result struct {
	ExitCode  int
	TimedOut  bool
	Truncated bool
	Cancelled bool
}

Result is how one command ended.

type Runner

type Runner struct {
	Binary         string
	APIURL         string
	Experimental   string
	Timeout        time.Duration
	MaxOutputBytes int64
	MaxLineBytes   int
	RunAsUser      string
}

Runner executes one vetted argv as the CLI binary, with no shell.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context, argv []string, token string, emit func(stream string, data []byte) error) (Result, error)

Run executes argv and streams output through emit, which is never called concurrently. ctx cancellation kills the whole process group.

Jump to

Keyboard shortcuts

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