pub enum AppEnv {
Development,
Staging,
Production,
}Expand description
The runtime environment a service runs in, read from the APP_ENV
environment variable.
Parsing is case-insensitive and accepts the common short aliases a
deployment platform might set: dev, stage/stg, prod. An unset
APP_ENV means Development — the safe default for
a workstation, and the one that permits the development shortcuts the
production guard later refuses.
Variants§
Development
A developer workstation or a local test. The default when APP_ENV is
unset. Development shortcuts are permitted here.
Staging
A pre-production environment that mirrors production. Shortcuts are permitted (staging is not the guarded environment) but should be rare.
Production
Real production traffic. The guard refuses development shortcuts here.
Implementations§
Source§impl AppEnv
impl AppEnv
Sourcepub fn from_process_env() -> Result<AppEnv, ConfigError>
pub fn from_process_env() -> Result<AppEnv, ConfigError>
Reads AppEnv from the process environment’s APP_ENV, defaulting to
Development when unset.
Returns a ConfigError naming APP_ENV when the value is set but
unrecognised, so a typo (APP_ENV=prod_uction) fails at startup rather
than silently downgrading to development.
Sourcepub fn is_development(self) -> bool
pub fn is_development(self) -> bool
True for Development.
Sourcepub fn is_staging(self) -> bool
pub fn is_staging(self) -> bool
True for Staging.
Sourcepub fn is_production(self) -> bool
pub fn is_production(self) -> bool
True for Production.
Sourcepub fn as_str(self) -> &'static str
pub fn as_str(self) -> &'static str
The canonical lowercase name of this environment ("development",
"staging", "production").
Sourcepub fn reject_dev_shortcut(
self,
name: &str,
enabled: bool,
) -> Result<(), ConfigError>
pub fn reject_dev_shortcut( self, name: &str, enabled: bool, ) -> Result<(), ConfigError>
The production-safety guard: refuses a development shortcut when running in production.
Call this for any flag that is convenient in development but dangerous
in production — allowing insecure TLS, seeding test data, exposing
internal error details to clients, disabling auth. When
self.is_production() && enabled, it returns a ConfigError naming
the offending flag; otherwise it is Ok.
use seiva_config::AppEnv;
// A dev-only flag left on in production is rejected...
let prod = AppEnv::Production;
assert!(prod.reject_dev_shortcut("ALLOW_INSECURE_TLS", true).is_err());
assert!(prod.reject_dev_shortcut("ALLOW_INSECURE_TLS", false).is_ok());
// ...but the same flag is fine in development.
let dev = AppEnv::Development;
assert!(dev.reject_dev_shortcut("ALLOW_INSECURE_TLS", true).is_ok());