Class: Contrast::Configuration
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
Contrast::Config::BaseConfiguration::AT_UNDERSCORE
Instance Attribute Summary collapse
Instance Method Summary
collapse
contrast_enter_method_scopes!, contrast_exit_method_scopes!, with_app_scope, with_contrast_scope, with_deserialization_scope, with_split_scope
#to_contrast_hash
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 cli_options = nil, default_name = DEFAULT_YAML_PATH
@default_name = default_name
config_kv = Contrast::Utils::HashUtils.deep_symbolize_all_keys(load_config)
cli_options ||= cli_to_hash
config_kv = Contrast::Utils::HashUtils.precedence_merge(config_kv, cli_options)
update_sources_from_cli(cli_options)
config_kv = update_prop_keys(config_kv)
@sources = Contrast::Components::Config::Sources.new(source_file_extensions)
@loaded_config = config_kv
create_config_components
end
|
Instance Attribute Details
111
112
113
|
# File 'lib/contrast/configuration.rb', line 111
def agent
@agent ||= Contrast::Components::Agent::Interface.new
end
|
106
107
108
|
# File 'lib/contrast/configuration.rb', line 106
def api
@api ||= Contrast::Components::Api::Interface.new
end
|
116
117
118
|
# File 'lib/contrast/configuration.rb', line 116
def application
@application ||= Contrast::Components::AppContext::Interface.new
end
|
126
127
128
|
# File 'lib/contrast/configuration.rb', line 126
def assess
@assess ||= Contrast::Components::Settings::Interface.new
end
|
#config_file ⇒ String?
56
57
58
|
# File 'lib/contrast/configuration.rb', line 56
def config_file
@config_file
end
|
#default_name ⇒ Object
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
|
131
132
133
|
# File 'lib/contrast/configuration.rb', line 131
def inventory
@inventory ||= Contrast::Components::Inventory::Interface.new
end
|
#loaded_config ⇒ Hash
52
53
54
|
# File 'lib/contrast/configuration.rb', line 52
def loaded_config
@loaded_config
end
|
136
137
138
|
# File 'lib/contrast/configuration.rb', line 136
def protect
@protect ||= Contrast::Components::Protect::Interface.new
end
|
121
122
123
|
# File 'lib/contrast/configuration.rb', line 121
def server
@server ||= Contrast::Config::ServerConfiguration.new
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]
extensions = Contrast::Components::Config::Sources::APP_CONFIGURATION_EXTENSIONS
paths = []
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
|
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
|
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
|