Envlet for Rust
One small crate. inject fills the process environment, load and get return values, all with typed errors.
Set up
Three steps. The host keeps one secret and everything else arrives at boot.
- 01
Install
One crate, typed errors.
Terminalcargo add envlet - 02
Set one secret
ENVLET_TOKEN in the environment of the binary.
Rust / production / environment variablesENVLET_TOKEN envlet_•••••••• the only secret the host keeps DATABASE_URL •••••••• moved to Envlet STRIPE_KEY •••••••• moved to Envlet SENTRY_DSN •••••••• moved to Envlet - 03
Inject at boot
Call inject(&Options::default())? before reading std::env.
main.rsuse envlet::{inject, Error, Options}; fn main() -> Result<(), Error> { inject(&Options::default())?; let stripe_key = std::env::var("STRIPE_KEY").unwrap(); Ok(()) }
Three calls
inject for most apps. load when you want a map. get when you want one value.
use envlet::{inject, Error, Options};
fn main() -> Result<(), Error> {
inject(&Options::default())?;
let stripe_key = std::env::var("STRIPE_KEY").unwrap();
Ok(())
}Typed
envlet types writes this file from the variables in your environment, with a load() that fills the shape below. Run it with --check in CI and a renamed variable fails the build.
envlet types
envlet types --check// Generated by envlet types for the "production" environment.
use std::collections::HashMap;
use envlet::{Error, Value};
pub struct Env {
pub database_url: String,
pub debug: bool,
pub flags: Option<envlet::serde_json::Value>,
pub mode: String,
pub port: i64,
pub stripe_key: String,
}Questions
Will my app start if Envlet is down?
No. The SDK retries for a few seconds, then fails so you notice. It never starts your app with half an environment.
What does the host need?
One variable, ENVLET_TOKEN. Everything else arrives at boot.
Can I still set some values on the Rust host?
Yes. A value the host already set wins. Pass override if you want Envlet to win instead.