validate

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package validate provides reusable, deterministic validators for user-supplied CLI inputs. It exists to make the CLI a safe target for AI agents and scripts, which can produce malformed or hostile input — control characters, path traversal, percent-encoding, embedded query parameters, shell metacharacters — in ways humans rarely do.

Validators return an *Error carrying a machine-classifiable Rule so callers can surface a precise, stable reason (and, in JSON output mode, a stable error code) instead of a generic "invalid input" message. Error() returns the bare reason so it composes cleanly when wrapped with caller context.

Index

Constants

View Source
const (
	RuleEmpty        = "empty"
	RuleControlChars = "control_chars"
	RuleEncoding     = "encoding"
	RuleEmbedded     = "embedded"
	RuleMetachars    = "metachars"
	RuleFormat       = "format"
	RuleRange        = "range"
)

Rule classifies why a value was rejected. The values are stable and intended to be surfaced as machine-readable error codes.

Variables

This section is empty.

Functions

func AuthToken

func AuthToken(value string) error

AuthToken validates a LocalStack auth token. The character set is intentionally not restricted — tokens are opaque — so only clearly malformed values are rejected: control characters, embedded whitespace, or an implausible length. An empty token is allowed (it means none is set). Callers should TrimSpace first, since environment injection (e.g. CI secrets) commonly appends a trailing newline.

func EnvVarName

func EnvVarName(name string) error

EnvVarName validates an environment variable name (the key of a KEY=VALUE pair).

func NoControlChars

func NoControlChars(field, value string) error

func PodName

func PodName(value string) error

PodName validates a Cloud Pod name against the platform's contract. The platform pattern has no length bound; the 128-character cap here is a local sanity limit against absurd inputs, not part of the platform contract. It runs ordered deny-checks so the most specific reason wins, then the allow-list. The deny-checks exist to give precise, machine-classifiable feedback; the allow-list alone would reject every invalid value.

func ServiceList

func ServiceList(value string) ([]string, error)

ServiceList validates and parses a comma-separated --services value. An empty string means "no filter" and returns (nil, nil) — equivalent to omitting the flag. Each item is trimmed of surrounding whitespace; duplicates are preserved (not deduplicated), matching the legacy CLI.

Types

type Error

type Error struct {
	Field string
	Rule  string
	Msg   string
}

func (*Error) Error

func (e *Error) Error() string

Jump to

Keyboard shortcuts

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