Module app_context

Module app_context 

Source
Expand description

Server-side runtime infrastructure context.

InfraContext is the bundle of per-site connection data passed through the service layer for every request: backend dispatcher, API base URLs, TLS cert, optional vault/k8s URLs, SOCKS proxy. It depends on StaticBackendDispatcher, which is server-only — the CLI never instantiates this.

§Lifetime

InfraContext<'a> borrows everything from ServerState: the backend dispatcher, URLs, root cert bytes, etc. live for the whole server lifetime, but the borrow is taken anew per request. Handlers obtain a context via state.infra_context(&site_name) (returning Result<InfraContext<'_>, Error>), then pass it by reference into the service layer:

let infra = state.infra_context(&site_name)?;
service::group::get_groups(&infra, &token, &params).await

The _ lifetime is tied to the state borrow, so an InfraContext cannot outlive the Arc<ServerState> that produced it.

§Typical usage

Service functions reach the backend through infra.backend.* (calling the trait method belonging to the desired interface, e.g. infra.backend.get_bootparameters(...)). When a function needs to build a direct CSM HTTP client — e.g. for IMS customize jobs that aren’t routed through the dispatcher — it uses infra.shasta_base_url, infra.shasta_root_cert, and infra.socks5_proxy together. Vault- and k8s-dependent paths gate on infra.vault_base_url / infra.k8s_api_url being Some; when either is None the handler returns 501.

Structs§

InfraContext
Infrastructure context needed by the service layer: backend dispatcher, API endpoints, and TLS certificates.