Documentation
¶
Overview ¶
Package env carries the per-run configuration envelope that used to live as loose package-level globals in utils/const.go.
Three access patterns are supported:
Context-attached (preferred) — call sites that already have a context.Context use env.From(ctx) to retrieve the run's config. The headless layer can attach a per-run *Env via env.With(ctx, env), so `ctk run --timeout 5m` does not pollute REPL state or other concurrent runs.
Process-active singleton (fallback) — capability methods that lack ctx (EventDump, parseRDSAccount) read env.Active(). Replaced atomically so concurrent reads see a consistent snapshot, unlike the previous unsynchronised globals.
Tests — env.SetActiveForTest pins a value and registers a cleanup that restores the previous active env, so 94 unit tests can keep using ListPolicies / Cloudlist / RDSAccount overrides without leaking state across t.Parallel boundaries.
From(ctx) prefers an attached env when present, falling back to Active(), finally to a zero-valued default. Callers therefore never have to nil-check.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetActive ¶
func SetActive(e *Env)
SetActive replaces the process-active env. cmd/main.go calls this once after runner.InitConfig; nothing else should call it at runtime. Pass nil to clear (Active reverts to Default).
func SetActiveForTest ¶
SetActiveForTest pins env as the active singleton and registers a cleanup that restores the prior value when the test ends. Use when a test needs to flip a single flag (ListPolicies, Cloudlist subset, ...) without fighting other tests.
Types ¶
type Env ¶
type Env struct {
LogEnable bool
ListPolicies bool
LogDir string
Cloudlist []string
IAMUserCheck string
RDSAccount string
RunTimeout time.Duration
}
Env is the per-run configuration envelope. Built once by the REPL or headless layer at startup; flows through context to providers and payloads.
All fields are read-only after construction. Callers must clone before mutating.
func Active ¶
func Active() *Env
Active returns the process-active env. Falls back to Default if nothing was set. Never returns nil.
func Default ¶
func Default() *Env
Default returns a zero-valued Env with sensible fallbacks. Used when neither ctx nor active singleton has anything attached (test environments, library embedding without InitConfig).