March Docs

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

fnputput(ns, key, value)#

Store a configuration value under (ns, key). ns is an atom naming your app.

fngetget(ns, key)#

Look up a configuration value. Returns Some(value) or None.

fnget_with_defaultget_with_default(ns, key, default_val)#

Get a configuration value, returning default if absent.

fnrequirerequire(ns, key)#

Get a required configuration value. Panics if not set.

fnput_input_in(ns, section, key, value)#

Store a configuration value under (ns, section, key).

fnget_inget_in(ns, section, key)#

Look up a 3-level configuration value. Returns Some(value) or None.

fnget_in_with_defaultget_in_with_default(ns, section, key, default_val)#

Get a 3-level configuration value, returning default if absent.

fnrequire_inrequire_in(ns, section, key)#

Get a required 3-level configuration value. Panics if not set.

fnfrom_envfrom_env(ns, key, env_var, default_val)#

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.

fnfrom_env_intfrom_env_int(ns, key, env_var, default_val)#

Load an Int value from an environment variable. Parses the string as an integer; uses default if absent or unparseable. Returns the value stored.

fnfrom_env_boolfrom_env_bool(ns, key, env_var, default_val)#

Load a Bool value from an environment variable. "true", "1", "yes" are parsed as true; uses default if absent. Returns the value stored.

fnenvenv()#

Returns the current application environment as an atom. Reads the MARCH_ENV environment variable; defaults to :dev. Possible values: :dev, :test, :prod.

fnis_devis_dev()#

True if the current environment is :dev.

fnis_testis_test()#

True if the current environment is :test.

fnis_prodis_prod()#

True if the current environment is :prod.

fnvalidatevalidate(ns, key, predicate)#

Validate a config value with a predicate function. Returns Ok(value) if the key is set and predicate returns true. Returns Err(reason) otherwise.

fnvalidate_invalidate_in(ns, section, key, predicate)#

Validate a 3-level config value with a predicate function. Returns Ok(value) or Err(reason).

fnput_endpointput_endpoint(port, host, secret)#

Store Bastion endpoint configuration. Typically called during application startup. Config.put_endpoint(4000, "localhost", secret)

fnendpoint_portendpoint_port(default_port)#

Get the configured HTTP port. Returns default_port if not set.

fnendpoint_hostendpoint_host(default_host)#

Get the configured host. Returns default_host if not set.

fnsecret_key_basesecret_key_base()#

Get the secret key base. Returns empty string if not configured.

fnnew_storenew_store(name)#

Create an isolated named config store. Useful for testing or multi-tenant configurations. Returns an opaque store handle (a Vault table).

fnstore_putstore_put(store, ns, key, value)#

Store a 2-level value in a named config store.

fnstore_getstore_get(store, ns, key)#

Look up a 2-level value from a named config store. Returns Some(v) or None.

fnstore_put_instore_put_in(store, ns, section, key, value)#

Store a 3-level value in a named config store.

fnstore_get_instore_get_in(store, ns, section, key)#

Look up a 3-level value from a named config store.