pub struct AppConfig {Show 24 fields
pub env: AppEnv,
pub app_name: String,
pub bind_addr: String,
pub database_url: String,
pub secret_key: String,
pub storage_dir: PathBuf,
pub assets_dir: PathBuf,
pub job_poll_interval_ms: u64,
pub job_concurrency: usize,
pub cookie_secure: bool,
pub webhooks_live: bool,
pub webhooks_allow_local: bool,
pub cors_origins: Vec<String>,
pub trust_proxy: bool,
pub metrics_token: Option<String>,
pub max_body_bytes: usize,
pub max_blob_bytes: usize,
pub csrf_enforce: bool,
pub slow_request_ms: u64,
pub slow_job_ms: u64,
pub git_sha: Option<String>,
pub incident_webhook_url: Option<String>,
pub incident_webhook_secret: Option<String>,
pub incident_stale_days: u64,
}Expand description
Runtime configuration loaded from SLABS_* and DATABASE_URL environment variables.
Fields§
§env: AppEnvDeployment environment (SLABS_ENV, default AppEnv::Development).
app_name: StringApplication name used for default database filenames, storage directories, and manifests.
bind_addr: StringSocket address to bind the HTTP server to (SLABS_BIND, default "127.0.0.1:3000").
database_url: StringConnection string for the primary database (DATABASE_URL, default "sqlite://{app_name}.db?mode=rwc").
secret_key: StringSecret key for signing cookies, tokens, and HMAC digests (SLABS_SECRET_KEY).
storage_dir: PathBufDirectory where uploaded blobs and local storage files are written (SLABS_STORAGE_DIR).
assets_dir: PathBufDirectory containing static assets such as CSS and JS files (SLABS_ASSETS_DIR).
job_poll_interval_ms: u64Polling interval in milliseconds for the background job worker (SLABS_JOB_POLL_MS, default 500).
job_concurrency: usizeMaximum number of background jobs executed concurrently (SLABS_JOB_CONCURRENCY, default 4).
Sets the Secure attribute on session cookies when true (SLABS_COOKIE_SECURE, default env.is_prod_like()).
webhooks_live: boolEnables live HTTP delivery for outbound webhooks when true (SLABS_WEBHOOKS_LIVE, default false).
webhooks_allow_local: boolAllows outbound webhooks to target loopback addresses when true (SLABS_WEBHOOKS_ALLOW_LOCAL, default false).
cors_origins: Vec<String>Allowed CORS origins loaded from comma-separated SLABS_CORS_ORIGINS.
trust_proxy: boolWhether to trust reverse-proxy forwarding headers (SLABS_TRUST_PROXY, default false).
metrics_token: Option<String>Optional bearer token protecting the metrics endpoint (SLABS_METRICS_TOKEN).
max_body_bytes: usizeMaximum HTTP request body size in bytes (SLABS_MAX_BODY_BYTES, default 4 MiB).
max_blob_bytes: usizeMaximum blob upload size in bytes (SLABS_MAX_BLOB_BYTES, default 10 MiB).
csrf_enforce: boolEnforces CSRF checks on cookie-authenticated mutations (SLABS_CSRF_ENFORCE, default true).
slow_request_ms: u64HTTP request latency threshold in milliseconds for slow-request incident capture (SLABS_SLOW_REQUEST_MS, default 500).
slow_job_ms: u64Background job execution latency threshold in milliseconds for slow-job incident capture (SLABS_SLOW_JOB_MS, default 5_000).
git_sha: Option<String>Optional Git commit SHA of the running build attached to runtime incidents (SLABS_GIT_SHA).
incident_webhook_url: Option<String>Optional webhook URL notified when a runtime incident is opened, re-opened, or resolved (SLABS_INCIDENT_WEBHOOK_URL).
incident_webhook_secret: Option<String>Optional HMAC-SHA256 signing secret for Incident Protocol v1 webhooks (SLABS_INCIDENT_WEBHOOK_SECRET).
incident_stale_days: u64Days of inactivity before active runtime incidents are auto-resolved (SLABS_INCIDENT_STALE_DAYS, default 30; 0 disables auto-closing).
Implementations§
Source§impl AppConfig
impl AppConfig
Sourcepub const DEV_SECRET_FALLBACK_SENTINEL: &str = "dev-only-change-me-in-production-slabs-secret-key"
pub const DEV_SECRET_FALLBACK_SENTINEL: &str = "dev-only-change-me-in-production-slabs-secret-key"
Legacy development fallback secret rejected by AppConfig::validate in staging and production.
Sourcepub fn from_env(app_name: impl Into<String>) -> Self
pub fn from_env(app_name: impl Into<String>) -> Self
Loads configuration from SLABS_* and DATABASE_URL environment variables.
Falls back to local development defaults derived from app_name when variables are unset.
When SLABS_SECRET_KEY is unset in development or test, generates a random ephemeral
32-byte hex key and logs a warning; in staging or production it leaves secret_key empty
so AppConfig::validate fails closed.
Sourcepub fn for_test(app_name: impl Into<String>, storage_dir: PathBuf) -> Self
pub fn for_test(app_name: impl Into<String>, storage_dir: PathBuf) -> Self
Builds an isolated configuration for parallel tests.
Uses env = AppEnv::Test, database_url = "sqlite::memory:", bind_addr = "127.0.0.1:0",
a 50ms job poll interval, and disables cookie_secure, webhooks_live, and webhooks_allow_local.
Sourcepub fn validate(&self) -> SlabResult<()>
pub fn validate(&self) -> SlabResult<()>
Validates configuration invariants, failing closed in staging and production environments.
Rejects missing, short (< 32 bytes), or sentinel SLABS_SECRET_KEY values when
self.env.is_prod_like() is true.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for AppConfig
impl<'de> Deserialize<'de> for AppConfig
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Forget for AppConfig
impl Freeze for AppConfig
impl Move for AppConfig
impl RefUnwindSafe for AppConfig
impl Send for AppConfigwhere
RawVecInner: Send,
impl Sync for AppConfigwhere
RawVecInner: Sync,
impl Unpin for AppConfig
impl UnsafeUnpin for AppConfigwhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
PhantomData<String>: UnsafeUnpin,
impl UnwindSafe for AppConfigwhere
RawVecInner: UnwindSafe,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more