Config + Secret from flags
id_effect_config already documents providers and Config descriptors. At a CLI edge, you usually:
- Parse a
--token/--api-keyflag (or read a path to a file). - Seed a
MapConfigProvider(orEnvConfigProvider) so the key matches what yourConfig::*descriptors expect. - Evaluate
Config::…inside anEffectwhoseRisConfigEnv(HCons<ConfigProviderService, HNil>), built withconfig_env(provider). - Wrap sensitive strings with
SecretviaConfig::secretso logs andDebugnever print raw material.
Minimal snippet
From examples/cli-minimal/src/lib.rs:
#![allow(unused)] fn main() { use id_effect::{Cause, Effect}; use id_effect_config::{Config, ConfigEnv, ConfigError, MapConfigProvider, Secret, config_env}; /// The `API_TOKEN` secret, loaded from the `ConfigEnv` capability. fn token_secret() -> Effect<Secret<String>, ConfigError, ConfigEnv> { Config::string("API_TOKEN") .secret() .run::<Secret<String>, ConfigError, ConfigEnv, _>() } /// The program and the matching environment, built from the flag. pub fn app_effect(token: String) -> (Effect<(), ConfigError, ConfigEnv>, ConfigEnv) { let provider = MapConfigProvider::from_pairs([("API_TOKEN", token.as_str())]); let env = config_env(provider); (token_secret().map(|_secret| ()), env) } /// A synchronous loader for callers outside any effect. pub fn load_token_secret(token: &str) -> Result<Secret<String>, Cause<ConfigError>> { let env = config_env(MapConfigProvider::from_pairs([("API_TOKEN", token)])); token_secret().provide_env(env).block_on().into_result() } assert!(load_token_secret("t0ken").is_ok()); let (eff, env) = app_effect("t0ken".to_owned()); assert!(eff.provide_env(env).block_on().into_result().is_ok()); }
main then calls run_main(eff, env, RunMainConfig::with_tracing()) (CLI with clap). The repository ships the full runnable layout under examples/cli-minimal (cli_minimal package in the workspace).
Operational notes
- Prefer short-lived exposure of secrets: parse → wrap in
Secret→ pass to effects; read the raw value only withSecret::expose, and avoid storing rawStringcopies in globals. - For file-based secrets, read bytes in an effect and wrap immediately; redact paths in error messages if they reveal usernames.
- Combine with CLI with clap for argv parsing and exit codes for
main.