Packages

A simple somewhat opinionated consul config provider for elixir 1.9+ releases.

Current section

Files

Jump to
consul_config_provider doc dist search_items-4b5c56ebbb.js
Raw

doc/dist/search_items-4b5c56ebbb.js

searchNodes=[{"doc":"A consul config provider for Elixir 1.9+ assuming the configs have an extension in the key name","ref":"ConsulConfigProvider.html","title":"ConsulConfigProvider","type":"module"},{"doc":"Http client using mojito","ref":"ConsulConfigProvider.Client.Mojito.html","title":"ConsulConfigProvider.Client.Mojito","type":"module"},{"doc":"behaviour for http commands used in the application for mox and to make the http layer plugable","ref":"ConsulConfigProvider.Http.html","title":"ConsulConfigProvider.Http","type":"behaviour"},{"doc":"","ref":"ConsulConfigProvider.Http.html#c:request/1","title":"ConsulConfigProvider.Http.request/1","type":"callback"},{"doc":"behaviour for transforming keyword values into any data types","ref":"ConsulConfigProvider.Transformer.html","title":"ConsulConfigProvider.Transformer","type":"behaviour"},{"doc":"","ref":"ConsulConfigProvider.Transformer.html#c:transform/1","title":"ConsulConfigProvider.Transformer.transform/1","type":"callback"},{"doc":"ConsulConfigProvider","ref":"readme.html","title":"ConsulConfigProvider","type":"extras"},{"doc":"The package can be installed by adding consul_config_provider to your list of dependencies in mix.exs:def deps do [ {:consul_config_provider, "~> 0.2"}, {:mojito, "~> 0.7"}, # default implmentation for http client ] endOnly add in mojito if you want to use the default http behaviour and not define your own clientThe docs can be found at https://hexdocs.pm/consul_config_provider.Sample UsageIn mix.exsreleases: [ release_name: [ include_executables_for: [:unix], applications: [ runtime_tools: :permanent, app_name_here: :permanent ], config_providers: [ {ConsulConfigProvider, %{prefix: "services/app_namespace_in_consul/v1", app_name: :app_name_here}} ] ] ],TransformerYou can also implement an optional transformer behaviour to change the form of your configs.This is helpful for interopt with erlang modules that might have different opinions about thingsdefmodule Example.Config do @behaviour ConsulConfigProvider.Transformer @impl true def transform({:erlkaf, [clients: [producer: [client_options: client_options]]]}) do default_client_options = Application.get_env(:erlkaf, :clients, []) |> Keyword.get(:producer, []) |> Keyword.get(:client_options, []) {:erlkaf, [ clients: [ producer: [ type: :producer, client_options: Keyword.merge(default_client_options, client_options) ] ] ]} end @impl true def transform(config), do: config endThen in your configs:config :consul_config_provider, transformer_module: Example.ConfigInformationThis provider assumes the config name has a file extension which is either .json, .yml, or .yaml no other extensions are supported although PRs would be welcomed. If you do not follow this naming convention the provider will not work and throw.In the above the prefix is used for the keys path and can also be set with CONSUL_PREFIX (provide an empty string to the prefix if you wish to just use the env var)The CONSUL_HOST env var is used for the host to talk to consul and defaults to localhostThe CONSUL_PORT env var is used for the port to talk to consul and defaults to 8500The http_module is dynamic and you can specify your own if you choose to do so. Just implement the HTTP behaviour and make your implementation return an {:ok, json_body_binary_string} as per the mojito example which will be the fallback. You might have to deal with coercing the input keyword list for the mojito arguments to support the client you are using, as well. You also need to set config :consul_config_provider, :http_module, Client.YourClient pointing to your client in your configs.Dependency-related configs are namespaced with their own application name while other configs use the input app_name for their namespace","ref":"readme.html#installation","title":"ConsulConfigProvider - Installation","type":"extras"}]