Config
Config module: layered application configuration backed by Vault.
Configuration is stored in a global, process-wide Vault table named "__march_config__", accessed via 2-atom or 3-atom tuple keys:
Config.put(:myapp, :port, 4000) Config.get(:myapp, :port) -- => Some(4000) Config.put_in(:myapp, :db, :host, "localhost") Config.get_in(:myapp, :db, :host) -- => Some("localhost")
Load from environment at startup: Config.from_env(:myapp, :port, "PORT", 4000) Config.from_env(:myapp, :secret, "SECRET_KEY_BASE", "")
Validate values: Config.validate(:myapp, :port, fn p -> p > 0 && p < 65536)
Detect current environment (reads MARCH_ENV): Config.env() -- :dev | :test | :prod
Endpoint config shorthand (for Bastion web server): Config.put_endpoint(4000, "localhost", my_secret) Config.endpoint_port(4000) Config.endpoint_host("localhost") Config.secret_key_base()
Named stores (for isolation in tests): let store = Config.new_store("my_test_store") Config.store_put(store, :myapp, :key, value) Config.store_get(store, :myapp, :key)
Functions
Store a configuration value under (ns, key). ns is an atom naming your app.
Look up a configuration value. Returns Some(value) or None.
Get a configuration value, returning default if absent.
Get a required configuration value. Panics if not set.
Store a configuration value under (ns, section, key).
Look up a 3-level configuration value. Returns Some(value) or None.
Get a 3-level configuration value, returning default if absent.
Get a required 3-level configuration value. Panics if not set.
Load a String value from an environment variable and store it in config. Uses default if the env var is not set. Returns the value stored.
Load an Int value from an environment variable. Parses the string as an integer; uses default if absent or unparseable. Returns the value stored.
Load a Bool value from an environment variable. "true", "1", "yes" are parsed as true; uses default if absent. Returns the value stored.
Returns the current application environment as an atom. Reads the MARCH_ENV environment variable; defaults to :dev. Possible values: :dev, :test, :prod.
True if the current environment is :dev.
True if the current environment is :test.
True if the current environment is :prod.
Validate a config value with a predicate function. Returns Ok(value) if the key is set and predicate returns true. Returns Err(reason) otherwise.
Validate a 3-level config value with a predicate function. Returns Ok(value) or Err(reason).
Store Bastion endpoint configuration. Typically called during application startup. Config.put_endpoint(4000, "localhost", secret)
Get the configured HTTP port. Returns default_port if not set.
Get the configured host. Returns default_host if not set.
Get the secret key base. Returns empty string if not configured.
Create an isolated named config store. Useful for testing or multi-tenant configurations. Returns an opaque store handle (a Vault table).
Store a 2-level value in a named config store.
Look up a 2-level value from a named config store. Returns Some(v) or None.
Store a 3-level value in a named config store.
Look up a 3-level value from a named config store.