Module: SecretConfig

Extended by:
Forwardable
Defined in:
lib/secret_config.rb,
lib/secret_config/cli.rb,
lib/secret_config/utils.rb,
lib/secret_config/config.rb,
lib/secret_config/errors.rb,
lib/secret_config/parser.rb,
lib/secret_config/railtie.rb,
lib/secret_config/version.rb,
lib/secret_config/registry.rb,
lib/secret_config/providers/ssm.rb,
lib/secret_config/providers/file.rb,
lib/secret_config/providers/provider.rb,
lib/secret_config/string_interpolator.rb,
lib/secret_config/setting_interpolator.rb

Overview

# Values are stripped of leading and trailing spaces.

Defined Under Namespace

Modules: Providers, Utils Classes: CLI, Config, ConfigurationError, Error, InvalidInterpolation, MissingEnvironmentVariable, MissingMandatoryKey, Parser, Railtie, Registry, SettingInterpolator, StringInterpolator, UndefinedRootError

Constant Summary collapse

NODE_KEY =

When a node is both a value and a hash/branch in the tree, put its value in its hash with the following key:

"__value__".freeze
FILTERED =
"[FILTERED]".freeze
RANDOM =
"$(random)".freeze
VERSION =
"1.0.0".freeze

Class Method Summary collapse

Class Method Details

.check_env_var=(check_env_var) ⇒ Object



95
96
97
# File 'lib/secret_config.rb', line 95

def self.check_env_var=(check_env_var)
  @check_env_var = check_env_var
end

.check_env_var?Boolean

Check the environment variables for a matching key and override the value returned from the central registry.

Returns:

  • (Boolean)


91
92
93
# File 'lib/secret_config.rb', line 91

def self.check_env_var?
  @check_env_var
end

.configure(path) {|config| ... } ⇒ Object

Fetch configuration in a block by supplying the root path once.

Example:

SecretConfig.configure("suppliers/kafka_service") do |config|
  Kafka::Client.new(
    seed_brokers:       config.fetch("brokers", separator: ","),
    delivery_interval:  config.fetch("delivery_interval", type: :integer, default: 0),
    delivery_threshold: config.fetch("delivery_threshold", type: :integer, default: 0),
    max_queue_size:     config.fetch("max_queue_size", type: :integer, default: 10_000),
    max_retries:        config.fetch("max_retries", type: :integer, default: -1),
    retry_backoffs:     config.fetch("retry_backoff", type: :integer, default: 0),
  )
end

If ‘SecretConfig.configure` was not used it would have looked like:

Kafka::Client.new(
  seed_brokers:       SecretConfig.fetch("suppliers/kafka_service/brokers", separator: ","),
  delivery_interval:  SecretConfig.fetch("suppliers/kafka_service/delivery_interval", type: :integer, default: 0),
  delivery_threshold: SecretConfig.fetch("suppliers/kafka_service/delivery_threshold", type: :integer, default: 0),
  max_queue_size:     SecretConfig.fetch("suppliers/kafka_service/max_queue_size", type: :integer, default: 10_000),
  max_retries:        SecretConfig.fetch("suppliers/kafka_service/max_retries", type: :integer, default: -1),
  retry_backoffs:     SecretConfig.fetch("suppliers/kafka_service/retry_backoff", type: :integer, default: 0),
)

Yields:

  • (config)


69
70
71
72
# File 'lib/secret_config.rb', line 69

def self.configure(path)
  config = Config.new(path, registry)
  yield(config)
end

.filtersObject

Filters to apply when returning the configuration



81
82
83
# File 'lib/secret_config.rb', line 81

def self.filters
  @filters
end

.filters=(filters) ⇒ Object



85
86
87
# File 'lib/secret_config.rb', line 85

def self.filters=(filters)
  @filters = filters
end

.registryObject

Returns the global registry. Unless ‘.use` was called above, it will default to a file provider.



76
77
78
# File 'lib/secret_config.rb', line 76

def self.registry
  @registry ||= SecretConfig::Registry.new
end

.use(provider, path: nil, **args) ⇒ Object

Which provider to use along with any arguments The path will be overriden by env var ‘SECRET_CONFIG_PATH` if present.



42
43
44
# File 'lib/secret_config.rb', line 42

def self.use(provider, path: nil, **args)
  @registry = SecretConfig::Registry.new(path: path, provider: provider, provider_args: args)
end