pub struct AppState { /* private fields */ }Expand description
Shared application state injected into every route handler via
axum::extract::State.
Implementations§
Source§impl AppState
impl AppState
Sourcepub fn new_with_tenant_db_dir(
commerce: Commerce,
tenant_db_dir: Option<PathBuf>,
) -> Self
pub fn new_with_tenant_db_dir( commerce: Commerce, tenant_db_dir: Option<PathBuf>, ) -> Self
Create a new AppState with optional per-tenant database directory.
Sourcepub fn with_tenant_db_dir(self, tenant_db_dir: impl Into<PathBuf>) -> Self
pub fn with_tenant_db_dir(self, tenant_db_dir: impl Into<PathBuf>) -> Self
Enable per-tenant SQLite routing under a base directory.
Sourcepub const fn with_ignore_tenant_header(self) -> Self
pub const fn with_ignore_tenant_header(self) -> Self
Ignore x-tenant-id headers when per-tenant routing is disabled.
By default, a request that carries x-tenant-id while no tenant
database directory is configured is rejected with a 400 so that
callers are never silently served shared data. Deployments that
intentionally sit behind a multi-tenant proxy (which forwards the
header but handles isolation upstream) can opt back into the old
silent fallthrough behavior with this escape hatch.
Sourcepub const fn ignores_tenant_header(&self) -> bool
pub const fn ignores_tenant_header(&self) -> bool
Whether x-tenant-id headers are ignored when tenant routing is disabled.
Sourcepub fn with_max_tenant_dbs(self, max_tenant_dbs: usize) -> Self
pub fn with_max_tenant_dbs(self, max_tenant_dbs: usize) -> Self
Set the maximum number of per-tenant databases kept in the active cache.
When capacity is reached, the least-recently-used idle tenant engine is evicted to make room for a new tenant. If every cached tenant engine is currently in use, creation of an additional tenant database is rejected.
Sourcepub fn with_metrics_bearer_auth(self, token: impl Into<String>) -> Self
pub fn with_metrics_bearer_auth(self, token: impl Into<String>) -> Self
Configure bearer authentication for the /metrics endpoint.
Sourcepub fn without_metrics_auth(self) -> Self
pub fn without_metrics_auth(self) -> Self
Disable authentication for /metrics.
Sourcepub fn with_metrics_ip_allowlist<I>(self, ips: I) -> Selfwhere
I: IntoIterator<Item = IpAddr>,
pub fn with_metrics_ip_allowlist<I>(self, ips: I) -> Selfwhere
I: IntoIterator<Item = IpAddr>,
Configure a client IP allowlist for /metrics.
Empty lists disable allowlist enforcement.
Sourcepub fn without_metrics_ip_allowlist(self) -> Self
pub fn without_metrics_ip_allowlist(self) -> Self
Disable IP allowlist checks for /metrics.
Sourcepub fn with_metrics_ip_cidr_allowlist<I>(self, cidrs: I) -> Selfwhere
I: IntoIterator<Item = IpCidr>,
pub fn with_metrics_ip_cidr_allowlist<I>(self, cidrs: I) -> Selfwhere
I: IntoIterator<Item = IpCidr>,
Configure a CIDR-based client IP allowlist for /metrics.
Empty lists disable CIDR allowlist enforcement.
Sourcepub fn without_metrics_ip_cidr_allowlist(self) -> Self
pub fn without_metrics_ip_cidr_allowlist(self) -> Self
Disable CIDR-based IP allowlist checks for /metrics.
Sourcepub fn with_metrics_trusted_proxies<I>(self, cidrs: I) -> Selfwhere
I: IntoIterator<Item = IpCidr>,
pub fn with_metrics_trusted_proxies<I>(self, cidrs: I) -> Selfwhere
I: IntoIterator<Item = IpCidr>,
Configure trusted proxy CIDRs for /metrics.
When configured, forwarded headers are only trusted when the request peer IP matches one of these networks.
Sourcepub fn without_metrics_trusted_proxies(self) -> Self
pub fn without_metrics_trusted_proxies(self) -> Self
Disable trusted proxy checks for /metrics.
Sourcepub const fn with_metrics_header_limits(
self,
limits: MetricsHeaderLimits,
) -> Self
pub const fn with_metrics_header_limits( self, limits: MetricsHeaderLimits, ) -> Self
Configure max accepted forwarding header lengths for /metrics.
Sourcepub fn tenant_db_dir(&self) -> Option<&Path>
pub fn tenant_db_dir(&self) -> Option<&Path>
Returns the configured tenant DB directory when per-tenant routing is enabled.
Sourcepub fn metrics_bearer_auth_token(&self) -> Option<&str>
pub fn metrics_bearer_auth_token(&self) -> Option<&str>
Return the configured bearer token for /metrics, if set.
Sourcepub fn metrics_ip_allowlist(&self) -> Option<Vec<IpAddr>>
pub fn metrics_ip_allowlist(&self) -> Option<Vec<IpAddr>>
Return configured metrics IP allowlist entries.
Sourcepub fn metrics_ip_cidr_allowlist(&self) -> Option<Vec<IpCidr>>
pub fn metrics_ip_cidr_allowlist(&self) -> Option<Vec<IpCidr>>
Return configured CIDR-based metrics IP allowlist entries.
Sourcepub fn metrics_ip_allowlist_len(&self) -> usize
pub fn metrics_ip_allowlist_len(&self) -> usize
Return number of configured exact-IP metrics allowlist entries.
Sourcepub fn metrics_ip_cidr_allowlist_len(&self) -> usize
pub fn metrics_ip_cidr_allowlist_len(&self) -> usize
Return number of configured CIDR metrics allowlist entries.
Sourcepub const fn has_metrics_ip_allowlist(&self) -> bool
pub const fn has_metrics_ip_allowlist(&self) -> bool
Returns whether /metrics IP allowlist checks are enabled.
Sourcepub fn metrics_trusted_proxies(&self) -> Option<Vec<IpCidr>>
pub fn metrics_trusted_proxies(&self) -> Option<Vec<IpCidr>>
Returns configured trusted proxy CIDRs.
Sourcepub fn metrics_trusted_proxies_len(&self) -> usize
pub fn metrics_trusted_proxies_len(&self) -> usize
Return number of configured trusted proxy CIDR entries.
Sourcepub const fn metrics_header_limits(&self) -> MetricsHeaderLimits
pub const fn metrics_header_limits(&self) -> MetricsHeaderLimits
Returns max accepted forwarding header lengths for /metrics.
Sourcepub const fn has_metrics_trusted_proxies(&self) -> bool
pub const fn has_metrics_trusted_proxies(&self) -> bool
Returns whether trusted proxy CIDRs are configured.
Sourcepub fn is_metrics_trusted_proxy(&self, ip: IpAddr) -> bool
pub fn is_metrics_trusted_proxy(&self, ip: IpAddr) -> bool
Check whether a peer IP is within configured trusted proxy CIDRs.
Sourcepub fn is_metrics_ip_allowed(&self, ip: IpAddr) -> bool
pub fn is_metrics_ip_allowed(&self, ip: IpAddr) -> bool
Check whether a metrics client IP is allowed by the configured allowlist.
Sourcepub fn tenant_cache_metrics(&self) -> TenantCacheMetrics
pub fn tenant_cache_metrics(&self) -> TenantCacheMetrics
Snapshot tenant cache runtime metrics.
Sourcepub fn commerce_for_tenant(
&self,
tenant_id: Option<&str>,
) -> Result<Arc<Commerce>, HttpError>
pub fn commerce_for_tenant( &self, tenant_id: Option<&str>, ) -> Result<Arc<Commerce>, HttpError>
Resolve the Commerce engine for a tenant.
When per-tenant routing is disabled, requests without a tenant id get
the default engine. Requests that do carry a tenant id are rejected
(the backend cannot isolate them), unless
Self::with_ignore_tenant_header was configured.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for AppState
impl !UnwindSafe for AppState
impl Freeze for AppState
impl Send for AppState
impl Sync for AppState
impl Unpin for AppState
impl UnsafeUnpin for AppState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ServiceExt for T
impl<T> ServiceExt for T
Source§fn compression(self) -> Compression<Self>where
Self: Sized,
fn compression(self) -> Compression<Self>where
Self: Sized,
compression-br or compression-deflate or compression-gzip or compression-zstd only.Source§fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
trace only.Source§fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
trace only.Source§fn follow_redirects(self) -> FollowRedirect<Self>where
Self: Sized,
fn follow_redirects(self) -> FollowRedirect<Self>where
Self: Sized,
follow-redirect only.Source§fn set_request_id<M>(
self,
header_name: HeaderName,
make_request_id: M,
) -> SetRequestId<Self, M>where
Self: Sized,
M: MakeRequestId,
fn set_request_id<M>(
self,
header_name: HeaderName,
make_request_id: M,
) -> SetRequestId<Self, M>where
Self: Sized,
M: MakeRequestId,
request-id only.Source§fn set_x_request_id<M>(self, make_request_id: M) -> SetRequestId<Self, M>where
Self: Sized,
M: MakeRequestId,
fn set_x_request_id<M>(self, make_request_id: M) -> SetRequestId<Self, M>where
Self: Sized,
M: MakeRequestId,
request-id only.x-request-id as the header name. Read moreSource§fn propagate_request_id(
self,
header_name: HeaderName,
) -> PropagateRequestId<Self>where
Self: Sized,
fn propagate_request_id(
self,
header_name: HeaderName,
) -> PropagateRequestId<Self>where
Self: Sized,
request-id only.Source§fn propagate_x_request_id(self) -> PropagateRequestId<Self>where
Self: Sized,
fn propagate_x_request_id(self) -> PropagateRequestId<Self>where
Self: Sized,
request-id only.x-request-id as the header name. Read more