Lamina.Provider.Env (lamina v0.2.2)

A configuration provider for retrieving information from the UNIX process environment.

Allows you to use process enviroment variables as application configuration.

This is a very simple wrapper around System.get_env/2. See the Elixir core documentation for more information.

Name mangling

We use a process called "name mangling" to convert an atom configuration key into the name of an environment variable. The default mangler (name_mangler/2) converts the configuration key into UPPER_SNAKE_CASE with an optional prefix.

Should you need to you can define your own mangler function and pass it as the :mangler option to this provider.

Examples

Given the following environment variables:

NameValue
PHOENIX_HTTP_PORT4000
BIND_ADDR0.0.0.0

We can retrieve the configurations from the environment:

iex> {:ok, state, _} = Env.init(prefix: "PHOENIX")
...> {:ok, "4000", :volatile, _state} = Env.fetch_config(:http_port, state)

iex> {:ok, state, _} = Env.init([])
...> {:ok, "0.0.0.0", :volatile, _state} = Env.fetch_config(:bind_addr, state)

Link to this section Summary

Functions

The default name mangler for environment variables.

Link to this section Types

Link to this type

lifetime_option()

Specs

lifetime_option() :: {:lifetime, Lamina.Provider.lifetime()}
Link to this type

mangler_option()

Specs

mangler_option() :: {:mangler, (atom(), any() -> String.t())}

Specs

Specs

options() :: [option()]
Link to this type

prefix_option()

Specs

prefix_option() :: {:prefix, String.t()}
Link to this type

refresh_period_option()

Specs

refresh_period_option() :: {:refresh_period, pos_integer()}

Specs

state() :: %{
  :mangler => (atom(), any() -> String.t()),
  :refresh_period => pos_integer(),
  :lifetime => Lamina.Provider.lifetime(),
  optional(:prefix) => String.t()
}

Link to this section Functions

Link to this function

name_mangler(config_key, arg2)

Specs

name_mangler(Lamina.config_key(), state()) :: String.t()

The default name mangler for environment variables.

Converts the configuration key into an upper-case underscored string, optionally with a prefix.

Examples:

iex> Env.name_mangler(:http_port, %{})
"HTTP_PORT"

iex> Env.name_mangler(:http_port, %{prefix: "phoenix"})
"PHOENIX_HTTP_PORT"