Documentation
¶
Overview ¶
Package config loads optional persistent defaults from a TOML file and merges them with CHROME_CDP_* environment variables into the effective global-flag defaults. Precedence, highest first: explicit flags > env > config file > built-in defaults. Cobra applies the flags; this package resolves the env > config > built-in portion and hands the result to the command tree.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Note ¶ added in v0.2.0
func Note() string
Note returns a one-line advisory about the config file, or "" when there is nothing to say. The CLI prints it to stderr before running.
It exists for one case: XDG_CONFIG_HOME is set and names a directory with no config file in it. That is how a policy disappears without anyone noticing — the CLI does not stop working, it simply stops being bounded, and there is no envelope field and no exit code to catch it. It cannot be made an error (running without a config file is the normal case for most users), so it is made visible.
Types ¶
type Defaults ¶
type Defaults struct {
Timeout time.Duration
// ConsentTimeout bounds the wait for Chrome's browser-modal "Allow remote
// debugging?" prompt (config key consent_timeout). It is separate from
// Timeout because it is not a command deadline at all: it is how long a
// human is given to find and click a dialog that may be behind the window,
// so it is measured in minutes where Timeout is measured in seconds.
ConsentTimeout time.Duration
By string
Wait string
Target string
Port int
ProfileDir string
NoLaunch bool
NoDaemon bool
JSON bool
NoColor bool
// Policy is the optional [policy] table (RFC-0012). No CHROME_CDP_* variable
// sets any of its keys: a safety boundary whose CONTENTS an inherited
// environment could rewrite would not be much of a boundary. Override it
// explicitly with --allow / --policy-off instead.
//
// It is not, however, immune to the environment, and pretending otherwise
// would be the more dangerous claim: XDG_CONFIG_HOME (and HOME) decide WHICH
// file is read, so an environment that points them elsewhere selects a
// different policy, or none. Nothing here can prevent that — the config file
// has to be found somehow — so the disappearance is made visible instead:
// Note() reports a config file that XDG_CONFIG_HOME pointed at and that does
// not exist, and an unreadable file becomes a Malformed policy the CLI
// refuses to run with rather than a policy silently absent.
Policy Policy
// Event-capture bounds for the observability verbs. They size the buffers
// the connection holder retains per tab, so they are read by the daemon (or
// by a --no-daemon connect) rather than by a command flag.
ConsoleBuffer int // retained console messages per tab
ConsoleMaxEntry int // per-message text cap, in bytes
NetBuffer int // retained network records per tab
NetMaxBody int // per-body cap, in bytes (request and response)
// Recording bounds (RFC-0011). A frame dwarfs a console line or a request
// record, so recording is bounded by BOTH a frame count and a byte ceiling:
// 600 frames is a modest number on a laptop viewport and a large one on a
// 4K monitor, and only the second bound knows the difference.
RecordBuffer int // retained frames per tab
RecordMaxBytes int // retained frame bytes per tab
}
Defaults are the effective global-flag defaults after the config file and CHROME_CDP_* env are merged over the built-in values.
func Builtin ¶
func Builtin() Defaults
Builtin returns the hard-coded defaults used when neither the config file nor the environment sets a value.
func FromEnv ¶
func FromEnv() Defaults
FromEnv returns the built-in defaults overlaid with CHROME_CDP_* env vars only (no config file). The daemon subprocess uses it: the parent already folded the config file into the environment it hands down, so parsing stays in one place.
type Policy ¶ added in v0.2.0
type Policy struct {
// Present reports that a [policy] table exists at all. With no table the
// whole layer is inert and nothing about the CLI changes.
Present bool
// Enabled defaults to true for a present table: a user who wrote the table
// meant it. Set enabled = false to keep it on file without applying it.
Enabled bool
Allow []string
Deny []string
ReadOnly []string
VerbsDenied []string
UploadRoots []string
AuditLog string
AuditAll bool
OnViolation string
// Malformed carries the reason a policy table could not be read: either the
// file did not parse at all while mentioning [policy], or the table held a
// key this build does not know.
//
// It exists because the repo's usual "warn and continue" is the wrong answer
// here. Continuing means running with a policy the user believes is in force
// and is not, and a policy that fails open is worse than no policy — so the
// CLI turns this into a refusal (RFC-0012 VS-15).
Malformed string
// Source is the config file the table came from, echoed in refusals so the
// user knows which file to edit.
Source string
}
Policy mirrors the [policy] table. It is raw, unvalidated data — parsing the patterns is internal/policy's job — but it does record enough for the CLI to refuse to run rather than run wide open (see Malformed).