env_var_provider v0.4.3 EnvVar.Provider

This provider loads a configuration from a map and uses that to set Application environment configuration with the values found in system environment variables. These variable names are constructed from the field names directly, following a convention.

Link to this section Summary

Functions

init is called by Distillery when running the provider during boostrap.

Link to this section Functions

Link to this function

convert(env_value, arg2)

init is called by Distillery when running the provider during boostrap.

prefix is a string that will me capitalized and prepended to all environment variables we look at. e.g. prefix: "beowulf" translates into environment variables starting with BEOWULF_. This is used to namespace our variables to prevent conflicts.

env_map follows the following format:

  env_map = %{
    heorot: %{
      location: %{type: :string, default: "land of the Geats"},
    },
    mycluster: %{
      server_count: %{type: :integer, default: "123"},
      name: %{type: :string, default: "grendel"},
      settings: %{type: {:list, :string}, default: "swarthy,hairy"},
      keys: %{type: {:tuple, :float}, default: "1.1,2.3,3.4"}
      no_default: %{type: :string}
    }
  }

Type conversion uses the defined types to handle the destination conversion.

Supported types:

  • :string
  • :integer
  • :float
  • {:tuple, <type>} - Complex type, where the second field is one of the simple types above. Currently items in the tuple must all be of the same type. A 3rd argument can be passed to specify the field separator in the env var. Defaults to comma.
  • {:list, <type>} - Complex type, following the same rules as Tuples above.

Default values will overwrite any existing values in the config for this environment.

Calling

init/1 expects to be passed a Keyword List of the form: init(prefix: "prefix", env_map: map, enforce: false)

The enforce argument specifies whether values with no default are all required. This will prevent any fallbacks to settings in the config files for values that are configured in the EnvVar Provider.

Link to this function

show_vars(opts)