ConfigurationService::Provider::Vault
A service provider for the Ruby ConfigurationService API.
Usage
The recommended approach to creating a configuration service client is to use a factory from the configuration_service gem. See the documentation for the ConfigurationService::Factory package for a list of available factories.
For example, we can use the ConfigurationService::Factory::EnvironmentContext factory to create and configure a configuration service client backed by the vault provider as follows.
Our main.rb (or config.ru or whatever) is simple:
require 'bundler'
Bundler.require(:default)
service = ConfigurationService::Factory::EnvironmentContext.create
configuraton = service.request_configuration
AcmeApplication.new(configuration.data).run
This relies on a bundler Gemfile to provide the configuration_service-provider-vault gem:
source 'https://rubygems.org'
gem 'configuration_service-provider-vault'
gem 'acme_application'
Now we use the process environment to configure the EnvironmentContext factory:
CFGSRV_IDENTIFIER="acme" \
CFGSRV_TOKEN="0b2a80f4-54ce-45f4-8267-f6558fee64af" \
CFGSRV_PROVIDER="vault" \
CFGSRV_PROVIDER_ADDRESS="http://127.0.0.1:8200" \
bundle exec main.rb
Note that main.rb is completely decoupled from the selection of provider and
provider configuration. We could swap and/or reconfigure the provider by
manipulating only the Gemfile and the environment.
If you insist on hard-coding everything, or if your strategy for bootstrapping the configuration service isn't expressed by an existing factory yet, you can construct the service yourself:
# Bad example
require 'configuration_service/provider/vault'
require 'acme_application'
service = ConfigurationService.new(
"acme",
"0b2a80f4-54ce-45f4-8267-f6558fee64af",
ConfigurationService::Provider::Vault.new(
address: "http://127.0.0.1:8200"
)
)
configuraton = service.request_configuration
AcmeApplication.new(configuration.data).run