Class: Contrast::Configuration
- Extended by:
- Contrast::Components::Scope::InstanceMethods, Forwardable
- Defined in:
- lib/contrast/configuration.rb
Overview
This is how we read in the local settings for the Agent, both ENV/ CMD line and from properties files, in order to determine which settings, if any, the user has overridden.
Constant Summary collapse
- CONTRAST_ENV_MARKER =
'CONTRAST__'
- DEFAULT_YAML_PATH =
'contrast_security.yaml'
- MILLISECOND_MARKER =
'_ms'
- CONVERSION =
{}.cs__freeze
- CONFIG_BASE_PATHS =
Precedence of paths, shift if config file values needs to go up the chain.
%w[./ config/ /etc/contrast/ruby/ /etc/contrast/ /etc/].cs__freeze
- KEYS_TO_REDACT =
%i[api_key url service_key user_name].cs__freeze
- REDACTED =
'**REDACTED**'
- EFFECTIVE_REDACTED =
'****'
- DEPRECATED_PROPERTIES =
%w[ CONTRAST__AGENT__SERVICE__ENABLE CONTRAST__AGENT__SERVICE__LOGGER__LEVEL CONTRAST__AGENT__SERVICE__LOGGER__PATH CONTRAST__AGENT__SERVICE__LOGGER__STDOUT ].cs__freeze
Constants included from Contrast::Config::BaseConfiguration
Contrast::Config::BaseConfiguration::AT_UNDERSCORE
Instance Attribute Summary collapse
- #agent ⇒ Contrast::Components::Agent::Interface
- #api ⇒ Contrast::Components::Api::Interface
- #application ⇒ Contrast::Components::AppContext::Interface
- #assess ⇒ Contrast::Components::Assess::Interface
- #config_file ⇒ String? readonly
-
#default_name ⇒ Object
readonly
Returns the value of attribute default_name.
- #enable ⇒ Boolean?
- #inventory ⇒ Contrast::Components::Inventory::Interface
- #loaded_config ⇒ Hash
- #protect ⇒ Contrast::Components::Protect::Interface
- #server ⇒ Contrast::Config::ServerConfiguration
- #sources ⇒ Contrast::Config::Sources
Instance Method Summary collapse
-
#configuration_paths ⇒ Object
Base paths to check for the contrast configuration file, sorted by reverse order of precedence (first is most important).
-
#initialize(cli_options = nil, default_name = DEFAULT_YAML_PATH) ⇒ Configuration
constructor
A new instance of Configuration.
-
#loggable ⇒ String
Get a loggable YAML format of this configuration.
-
#origin ⇒ Contrast::Config::ConfigurationFiles
List of all read configuration files.
-
#source_file_extensions ⇒ Hash
Map of all extensions for each config key.
Methods included from Contrast::Components::Scope::InstanceMethods
contrast_enter_method_scopes!, contrast_exit_method_scopes!, with_app_scope, with_contrast_scope, with_deserialization_scope, with_split_scope
Methods included from Contrast::Config::BaseConfiguration
Constructor Details
#initialize(cli_options = nil, default_name = DEFAULT_YAML_PATH) ⇒ Configuration
Returns a new instance of Configuration.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/contrast/configuration.rb', line 73 def initialize = nil, default_name = DEFAULT_YAML_PATH @default_name = default_name # Load config_kv from file config_kv = Contrast::Utils::HashUtils.deep_symbolize_all_keys(load_config) # Load cli options from env ||= cli_to_hash config_kv = Contrast::Utils::HashUtils.precedence_merge(config_kv, ) update_sources_from_cli() # Some in-flight rewrites to maintain backwards compatibility config_kv = update_prop_keys(config_kv) @sources = Contrast::Components::Config::Sources.new(source_file_extensions) @loaded_config = config_kv # requires loaded_config: create_config_components end |
Instance Attribute Details
#agent ⇒ Contrast::Components::Agent::Interface
111 112 113 |
# File 'lib/contrast/configuration.rb', line 111 def agent @agent ||= Contrast::Components::Agent::Interface.new # rubocop:disable Naming/MemoizedInstanceVariableName end |
#api ⇒ Contrast::Components::Api::Interface
106 107 108 |
# File 'lib/contrast/configuration.rb', line 106 def api @api ||= Contrast::Components::Api::Interface.new # rubocop:disable Naming/MemoizedInstanceVariableName end |
#application ⇒ Contrast::Components::AppContext::Interface
116 117 118 |
# File 'lib/contrast/configuration.rb', line 116 def application @application ||= Contrast::Components::AppContext::Interface.new # rubocop:disable Naming/MemoizedInstanceVariableName end |
#assess ⇒ Contrast::Components::Assess::Interface
126 127 128 |
# File 'lib/contrast/configuration.rb', line 126 def assess @assess ||= Contrast::Components::Settings::Interface.new # rubocop:disable Naming/MemoizedInstanceVariableName end |
#config_file ⇒ String? (readonly)
56 57 58 |
# File 'lib/contrast/configuration.rb', line 56 def config_file @config_file end |
#default_name ⇒ Object (readonly)
Returns the value of attribute default_name.
33 34 35 |
# File 'lib/contrast/configuration.rb', line 33 def default_name @default_name end |
#enable ⇒ Boolean?
50 51 52 |
# File 'lib/contrast/configuration.rb', line 50 def enable @enable end |
#inventory ⇒ Contrast::Components::Inventory::Interface
131 132 133 |
# File 'lib/contrast/configuration.rb', line 131 def inventory @inventory ||= Contrast::Components::Inventory::Interface.new # rubocop:disable Naming/MemoizedInstanceVariableName end |
#loaded_config ⇒ Hash
52 53 54 |
# File 'lib/contrast/configuration.rb', line 52 def loaded_config @loaded_config end |
#protect ⇒ Contrast::Components::Protect::Interface
136 137 138 |
# File 'lib/contrast/configuration.rb', line 136 def protect @protect ||= Contrast::Components::Protect::Interface.new # rubocop:disable Naming/MemoizedInstanceVariableName end |
#server ⇒ Contrast::Config::ServerConfiguration
121 122 123 |
# File 'lib/contrast/configuration.rb', line 121 def server @server ||= Contrast::Config::ServerConfiguration.new # rubocop:disable Naming/MemoizedInstanceVariableName end |
#sources ⇒ Contrast::Config::Sources
54 55 56 |
# File 'lib/contrast/configuration.rb', line 54 def sources @sources end |
Instance Method Details
#configuration_paths ⇒ Object
Base paths to check for the contrast configuration file, sorted by reverse order of precedence (first is most important).
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/contrast/configuration.rb', line 142 def configuration_paths @_configuration_paths ||= begin basename = default_name.split('.')[0] # Order of extensions comes from here: extensions = Contrast::Components::Config::Sources::APP_CONFIGURATION_EXTENSIONS paths = [] # Environment paths takes precedence here. Look first through them. config_path = ENV.fetch('CONTRAST_CONFIG_PATH', nil) security_path = ENV.fetch('CONTRAST_SECURITY_CONFIG', nil) paths << config_path if config_path paths << security_path if security_path extensions.each do |ext| places = CONFIG_BASE_PATHS.product(["#{ basename }.#{ ext }"]) paths += places.map!(&:join) end paths end end |
#loggable ⇒ String
Get a loggable YAML format of this configuration
96 97 98 |
# File 'lib/contrast/configuration.rb', line 96 def loggable convert_to_hash.to_yaml end |
#origin ⇒ Contrast::Config::ConfigurationFiles
List of all read configuration files.
166 167 168 |
# File 'lib/contrast/configuration.rb', line 166 def origin @_origin ||= Contrast::Config::ConfigurationFiles.new end |
#source_file_extensions ⇒ Hash
Returns map of all extensions for each config key.
101 102 103 |
# File 'lib/contrast/configuration.rb', line 101 def source_file_extensions @_source_file_extensions ||= {} end |