Module: ContainerConfig

Defined in:
lib/container_config.rb,
lib/container_config/rails.rb,
lib/container_config/redis.rb,
lib/container_config/logger.rb,
lib/container_config/coercer.rb,
lib/container_config/version.rb,
lib/container_config/provider.rb,
lib/container_config/coercer/base.rb,
lib/container_config/provider/env.rb,
lib/container_config/rails/mailer.rb,
lib/container_config/coercer/float.rb,
lib/container_config/provider/base.rb,
lib/container_config/coercer/string.rb,
lib/container_config/coercer/symbol.rb,
lib/container_config/coercer/boolean.rb,
lib/container_config/coercer/integer.rb,
lib/container_config/coercer/ssl_key.rb,
lib/container_config/provider/default.rb,
lib/container_config/provider/secret_volume.rb,
lib/container_config/coercer/ssl_certificate.rb,
lib/container_config/coercer/ssl_verify_mode.rb,
lib/container_config/provider/rails_credential.rb

Overview

Contains methods for loading and parsing container configuration

Defined Under Namespace

Modules: Coercer, Provider, Rails, Redis Classes: Error, InvalidEnumValue, Logger, MissingOverride, MissingRequiredValue

Constant Summary collapse

VERSION =

ContainerConfig version

"0.1.1"

Class Method Summary collapse

Class Method Details

.cacheHash

Gets the configuration cache



61
62
63
# File 'lib/container_config.rb', line 61

def self.cache
  @cache ||= {}
end

.clear_cacheObject

Clears all entries from the configuration cache



52
53
54
# File 'lib/container_config.rb', line 52

def self.clear_cache
  @cache = {}
end

.coercersArray<ContainerConfig::Coercer::Base>

Gets the list of configuration value coercers



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

def self.coercers
  @coercers ||= ContainerConfig::Coercer.default_coercers
end

.coercers=(coercers) ⇒ Object

Sets the list of configuration value coercers



79
80
81
# File 'lib/container_config.rb', line 79

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

.load(key, *dig_keys, **options) ⇒ Object

Loads a configuration setting from environment variables, mounted secrets, or the application credentials

Options Hash (**options):

  • :required (Boolean)

    whether to raise an exception if the setting cannot be found

  • :default (String)

    default value if the configuration setting cannot be found

  • :secret_mount_directory (String)

    directory where secret files are mounted

  • :coerce_nil (Boolean)

    where to coerce nil values (defaults to true)

  • :cache (Boolean)

    whether to cache the retrieved value and to return that value in future calls future calls must also specify cache: true to prevent the value from being re-read

  • :type (Symbol)

    type to use such as :boolean, :integer, :string, :symbol, :ssl_verify_mode, :ssl_certificate, or :ssl_key

  • :enum (Array)

    valid values for the configuration parameter, raises an exception if the value is not in the enum



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/container_config.rb', line 32

def self.load(key, *dig_keys, **options)
  logger.debug { "Loading configuration value for #{key}" }
  options[:required] ||= options[:raise] || false
  dig_keys = key.downcase.split("_") if dig_keys.empty?

  return cache[key] if options[:cache] && cache.key?(key)

  config_value = ContainerConfig::Provider.load_value(key, *dig_keys, **options)
  handle_empty_value(config_value, key, **options)
  config_value = ContainerConfig::Coercer.coerce_value(config_value, options[:type], **options)
  handle_enum(config_value, **options)

  cache[key] = config_value if options[:cache]

  config_value
end

.log_formatter::Logger::Formatter

Gets the container config log formatter



128
129
130
# File 'lib/container_config.rb', line 128

def self.log_formatter
  @log_formatter ||= logger.formatter
end

.log_formatter=(log_formatter) ⇒ Object

Sets the container config log formatter



137
138
139
140
# File 'lib/container_config.rb', line 137

def self.log_formatter=(log_formatter)
  @log_formatter = log_formatter
  logger.formatter = log_formatter
end

.loggerContainerConfig::Logger

Gets the container config logger



106
107
108
# File 'lib/container_config.rb', line 106

def self.logger
  @logger ||= ContainerConfig::Logger.new($stdout, level: Logger::INFO)
end

.logger=(logger) ⇒ Object

Sets the container config logger



115
116
117
118
119
120
121
# File 'lib/container_config.rb', line 115

def self.logger=(logger)
  if logger.nil?
    self.logger.level = Logger::FATAL
    return self.logger
  end
  @logger = logger
end

.providersArray<ContainerConfig::Provider::Base>

Gets the list of configuration value providers



88
89
90
# File 'lib/container_config.rb', line 88

def self.providers
  @providers ||= ContainerConfig::Provider.default_providers
end

.providers=(providers) ⇒ Object

Sets the list of configuration value providers



97
98
99
# File 'lib/container_config.rb', line 97

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

.rails_app?Boolean

Whether this is in the context of a Rails application



147
148
149
# File 'lib/container_config.rb', line 147

def self.rails_app?
  defined?(::Rails) && ::Rails.respond_to?(:application)
end