Module: ConfigurationService::Factory

Defined in:
lib/configuration_service/factory.rb,
lib/configuration_service/factory/context.rb,
lib/configuration_service/factory/yaml_file_context.rb,
lib/configuration_service/factory/environment_context.rb,
lib/configuration_service/factory/context/symbolic_access_wrapper.rb,
lib/configuration_service/factory/environment_context_backward_compatibility.rb

Overview

A factory for creating a configuration service client

Examples:

Requesting configuration from the Vault service provider


# With the following in the environment:
#
# CFGSRV_IDENTIFIER="acme"
# CFGSRV_TOKEN="0b2a80f4-54ce-45f4-8267-f6558fee64af"
# CFGSRV_PROVIDER="vault"
# CFGSRV_PROVIDER_ADDRESS="http://127.0.0.1:8200"

# And the following in Gemfile:
#
# source 'https://rubygems.org'
#
# gem 'configuration_service-provider-vault'
# gem 'acme_application'

# Now main.rb (or config.ru or whatever) is decoupled from provider
# selection and service configuration:

require 'bundler'
Bundler.require(:default) # Registers the vault provider

configuration_service = ConfigurationService::Factory.create_client
configuraton = configuration_service.request_configuration
AcmeApplication.new(configuration.data).run

Creating an AdminClient with static bootstrap configuration


admin_client = ConfigurationService::Factory.create_admin_client(
  "token" => "c3935418-f621-40de-ada3-cc8169f1348a",
  "provider_id" => "vault",
  "provider_config" => {
    "address" => "http://127.0.0.1:8200"
  }
)

Defined Under Namespace

Modules: EnvironmentContextBackwardCompatibility Classes: Context, EnvironmentContext, YamlFileContext

Class Method Summary collapse

Class Method Details

.create_admin_client(context = EnvironmentContext.new) ⇒ ConfigurationService::AdminClient

Create a configuration service admin client

When the context is a Hash, it is wrapped in a Context, which does not scrub sources after the configuration service client is created. For this reason, the process ENV should never be given as the context; rather give no context, so that the default EnvironmentContext will be used to safely scrub the process ENV and (on JRuby) system properties after the configuration service client is created.

Because the AdminClient operates over multiple configuration identifiers, it does not require an identifier property from the context.

Parameters:

Returns:



83
84
85
86
87
88
89
# File 'lib/configuration_service/factory.rb', line 83

def self.create_admin_client(context = EnvironmentContext.new)
  context = Context.new(context) if context.is_a?(Hash)
  provider = create_provider(context)
  ConfigurationService::AdminClient.new(context.token, provider)
ensure
  context.scrub!
end

.create_client(context = EnvironmentContext.new) ⇒ ConfigurationService::Base

Create a configuration service client

When the context is a Hash, it is wrapped in a Context, which does not scrub sources after the configuration service client is created. For this reason, the process ENV should never be given as the context; rather give no context, so that the default EnvironmentContext will be used to safely scrub the process ENV and (on JRuby) system properties after the configuration service client is created.

The context must provide an identifier property.

Parameters:

Returns:



60
61
62
63
64
65
66
# File 'lib/configuration_service/factory.rb', line 60

def self.create_client(context = EnvironmentContext.new)
  context = Context.new(context) if context.is_a?(Hash)
  provider = create_provider(context)
  ConfigurationService::Base.new(context.identifier, context.token, provider)
ensure
  context.scrub!
end