distillery v2.0.0-rc.1 Mix.Releases.Config.Provider behaviour
This defines the behaviour for custom configuration providers.
Link to this section Summary
Functions
Given a file path, this function expands it to an absolute path, while also expanding any environment variable references in the path
Callbacks
Called when the provider is being asked to supply a value for the given key
Called when the provider is initialized
Link to this section Functions
Given a file path, this function expands it to an absolute path, while also expanding any environment variable references in the path.
Examples
iex> var = String.replace("Elixir.Mix.Releases.Config.Provider", ".", "_")
...> System.put_env(var, "hello")
...> {:ok, "var/hello/test"} = Elixir.Mix.Releases.Config.Provider.expand_path("var/${" <> var <> "}/test")
iex> {:ok, "/" <> _} = Elixir.Mix.Releases.Config.Provider.expand_path("~/")
iex> {:error, :unclosed_var_expansion} = Elixir.Mix.Releases.Config.Provider.expand_path("var/${FOO/test")
Link to this section Callbacks
Called when the provider is being asked to supply a value for the given key
Keys supplied to providers are a list of atoms which represent the path of the configuration key, beginning with the application name:
NOTE: This is currently unused, but provides an API for fetching config values from specific providers, which may come in handy down the road. A default implementation is provided for you, which fetches values from the application environment.
Examples
> MyProvider.get([:myapp, :server, :port])
{:ok, 8080}
> MyProvider.get([:maypp, :invalid, :key])
nil
Called when the provider is initialized.
This function is called early during the boot sequence, after all applications are loaded,
but only :kernel
, :stdlib
, :compiler
, and :elixir
are started. This means that you
cannot expect supervisors and processes to be running. You may need to start them manually,
or start entire applications manually, but it is critical that you stop them before returning
from init/1
, or the boot sequence will fail post-configuration.
The arguments given to init/1
are the same as given in the config_providers
setting in
your release configuration file.
NOTE: It is recommended that you use init/1
to load configuration and then
persist it into the application environment, e.g. with
Application.put_env/3
. This ensures that applications need not be aware of
your specific configuration provider.