config

package
v0.233.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package config loads runtime settings from environment variables.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Specification

type Specification struct {
	HTTPAddress     string         `env:"HTTP_ADDR" envDefault:"127.0.0.1:8080"`
	HTTPSAddress    string         `env:"HTTPS_ADDR" envDefault:"127.0.0.1:8443"`
	TLS             tlscert.Config // Nested: env tags live on tlscert.Config itself.
	SigningKeyFile  string         `env:"SIGNING_KEY_FILE"`
	IssuerURL       string         `env:"ISSUER_URL" envDefault:"https://localhost:8443/"`
	DefaultAudience string         `env:"DEFAULT_AUDIENCE" envDefault:"https://localhost:8443/api/v2/"` // Blank: no default audience.
	AccessTokenTTL  time.Duration  `env:"ACCESS_TOKEN_TTL" envDefault:"24h"`
	IDTokenTTL      time.Duration  `env:"ID_TOKEN_TTL" envDefault:"24h"`
	// AdminAllowRemote lets the mock listen on an address other machines can
	// reach. Off by default because /admin0 is unauthenticated.
	AdminAllowRemote bool `env:"ADMIN_ALLOW_REMOTE" envDefault:"false"`
	// TokenLeeway is the clock skew tolerated on exp/nbf/iat checks.
	TokenLeeway time.Duration `env:"TOKEN_LEEWAY" envDefault:"0s"`
	LogLevel    string        `env:"LOG_LEVEL" envDefault:"info"`
	// Debug turns on the request/response dump middleware. Off by default;
	// enables full method/path/query/headers/body logging for every
	// request + response at INFO level. Authorization + Cookie headers are
	// redacted; bodies are truncated at 8 KiB. Local-dev only — adds an
	// allocation and a synchronous log write per request.
	Debug                bool          `env:"DEBUG" envDefault:"false"`
	SpecValidationStrict bool          `env:"SPEC_VALIDATION_STRICT" envDefault:"true"`
	ReadHeaderTimeout    time.Duration `env:"READ_HEADER_TIMEOUT" envDefault:"5s"`
	WriteTimeout         time.Duration `env:"WRITE_TIMEOUT" envDefault:"30s"`
	IdleTimeout          time.Duration `env:"IDLE_TIMEOUT" envDefault:"120s"`
	MaxRequestBodyBytes  int64         `env:"MAX_REQUEST_BODY_BYTES" envDefault:"1048576"` // 1 MiB.
	ShutdownTimeout      time.Duration `env:"SHUTDOWN_TIMEOUT" envDefault:"5s"`

	// EventsReplayBuffer caps the SSE replay ring buffer at GET /events.
	// Reconnecting subscribers can resume from Last-Event-ID, ?from, or
	// ?from_timestamp up to this many events back. <= 0 disables replay
	// (the endpoint still works; resume params become no-ops).
	EventsReplayBuffer int `env:"EVENTS_REPLAY_BUFFER" envDefault:"100"`

	// RequestJournalSize caps the in-memory journal of /api/v2 calls served
	// at GET /admin0/journal. <= 0 disables recording (the endpoints then
	// return an empty list; the no_match 404 hint is unaffected).
	RequestJournalSize int `env:"REQUEST_JOURNAL_SIZE" envDefault:"1000"`

	// EventsReconnectHint is the SSE `retry:` reconnect-delay hint sent to
	// GET /events subscribers on connect (Auth0's Events API sends one
	// too). 0 omits the hint, so clients fall back to their built-in
	// default (EventSource ≈ 3s).
	EventsReconnectHint time.Duration `env:"EVENTS_RECONNECT_HINT" envDefault:"3s"`

	// LogoutAllowedURLs is the comma-separated allow-list of absolute
	// URLs that /v2/logout (returnTo) and /oidc/logout
	// (post_logout_redirect_uri) will redirect to. Relative URLs are
	// always allowed (they can't escape the mock's origin). Mirrors
	// Auth0's "Allowed Logout URLs" tenant setting.
	LogoutAllowedURLs []string `env:"LOGOUT_ALLOWED_URLS" envSeparator:","`

	// AuthorizeAllowedCallbacks is the comma-separated allow-list of
	// absolute redirect_uri values that /authorize will 302 to. Same
	// threat model as LogoutAllowedURLs but on the higher-value endpoint:
	// /authorize carries `code` / `access_token` in the URL, so an
	// unvalidated redirect_uri leaks them to attacker-controlled hosts.
	// Mirrors Auth0's per-application "Allowed Callback URLs" setting.
	// Empty = no enforcement (the test-friendly default — clients can
	// register any callback).
	AuthorizeAllowedCallbacks []string `env:"AUTHORIZE_ALLOWED_CALLBACKS" envSeparator:","`

	// CORSAllowedOrigins is the comma-separated allow-list of browser
	// origins (scheme://host[:port]) that may call the mock cross-origin.
	// `*.` as the first host label (https://*.example.com) matches exactly
	// one subdomain level; `*` alone allows any origin. Mirrors Auth0's
	// per-application "Allowed Web Origins" / "Allowed Origins (CORS)"
	// settings. Empty = any origin is allowed (the test-friendly default).
	CORSAllowedOrigins []string `env:"CORS_ALLOWED_ORIGINS" envSeparator:","`

	// BearerRequireAudience opts the Mgmt-API bearer middleware into Auth0-
	// like strict audience binding. When non-empty, tokens whose `aud`
	// claim doesn't contain this value get a 401. Empty (default) keeps
	// the "echoed, not enforced" behaviour the README documents so test
	// suites can swap audiences freely.
	BearerRequireAudience string `env:"BEARER_REQUIRE_AUDIENCE"`
}

Specification holds all runtime settings.

func Load

func Load() (*Specification, error)

Load populates a Specification from process environment and validates it. Errors out on impossible combinations like "both listeners disabled" so callers don't have to repeat the sanity checks (and so the process doesn't silently idle forever waiting for a signal that nothing's listening for).

func (*Specification) RemoteListeners added in v0.233.0

func (s *Specification) RemoteListeners() []string

RemoteListeners returns the enabled listeners that other machines can reach, as NAME=value entries with HTTP first.

func (*Specification) Validate

func (s *Specification) Validate() error

Validate checks the loaded Specification for mutually-exclusive or nonsensical combinations. Run automatically by Load(); exported so callers building a Specification programmatically (tests, embeds) get the same sanity net.

Jump to

Keyboard shortcuts

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