Skip to main content

default_audience_from_env

Function default_audience_from_env 

Source
pub fn default_audience_from_env(prefix: &str) -> Result<String, Error>
Expand description

Resolves {prefix}_DEFAULT_AUDIENCE (falling back to MICROMEGAS_DEFAULT_AUDIENCE) – the deployment default audience, defaulting to PUBLIC_AUDIENCE when unset. Resolved once at startup (web_server.rs) so a typo fails fast rather than surfacing as a per-request 400. Empty or otherwise invalid ⇒ Err: with one knob there is no “unset” state left for an empty string to mean, so a blank value is a misconfiguration, not an opt-out.

Leading/trailing whitespace is trimmed and warn!-logged, the same way the other two readers of this same variable handle it, so one env value can never be accepted by one role and rejected by another. Trimming keeps a value a deployment template rendered with stray padding working; the warning stays because padding is far more likely a templating slip than an intention.

One knob, one meaning: the audience anything that arrives without one gets. There are three code readers today (not deployment roles – a role can build more than one of these): this function (key mint), micromegas_analytics::audience::default_audience_from_env (read once by LakehouseContext::new and handed to the three Postgres read sites), and the ingestion HTTP edge’s own call in serve_ingestion, which resolves the default a credential with no bound audience is stamped with at write time. This is what ingestion_keys.rs::resolve_audience falls back to on the mint route.