lib/contrast/components/config.rb in contrast-agent-6.6.5 vs lib/contrast/components/config.rb in contrast-agent-6.7.0
- old
+ new
@@ -32,10 +32,13 @@
"Setting both application.session_id and application.session_metadata is not allowed.\n"
API_URL = "Invalid configuration. Missing a required connection value 'url' is not set."
API_KEY = "Invalid configuration. Missing a required connection value 'api_key' is not set."
API_SERVICE_KEY = "Invalid configuration. Missing a required connection value 'service_tag' is not set."
API_USERNAME = "Invalid configuration. Missing a required connection value 'user_name' is not set."
+
+ attr_reader :config
+
def initialize
build
end
# Basic logger for handling configuration validation logging
@@ -60,20 +63,59 @@
rescue ArgumentError => e
proto_logger.error('Configuration failed with error: ', e)
end
alias_method :rebuild, :build
- # @return [Contrast::Config::RootConfiguration]
- def root
- @config.root
+ # @return [Contrast::Components::Api::Interface]
+ def api
+ @config.api
end
+ # @return [Contrast::Components::Agent::Interface]
+ def agent
+ @config.agent
+ end
+
+ # @return [Contrast::Components::AppContext::Interface]
+ def application
+ @config.application
+ end
+
+ # @return [Contrast::Config::ServerConfiguration]
+ def server
+ @config.server
+ end
+
+ # @return [Contrast::Components::Assess::Interface]
+ def assess
+ @config.assess
+ end
+
+ # @return [Contrast::Components::Inventory::Interface]
+ def inventory
+ @config.inventory
+ end
+
+ # @return [Contrast::Components::Protect::Interface]
+ def protect
+ @config.protect
+ end
+
+ # @return [Contrast::Components::Service::Interface]
+ def service
+ @config.service
+ end
+
def valid?
@_valid = validate if @_valid.nil?
@_valid
end
+ def enable
+ @config.enable
+ end
+
def invalid?
!valid?
end
def loggable
@@ -83,16 +125,16 @@
# Typically, this would be accessed through Contrast::SETTINGS, but we're specifically checking for the user
# provided value here rather than that echoed back by TeamServer.
#
# @return [String,nil] the value of the session id set in the configuration, or nil if unset
def session_id
- root.application.session_id
+ application.session_id
end
# @return [String,nil] the value of the session metadata set in the configuration, or nil if unset
def session_metadata
- root.application.session_metadata
+ application.session_metadata
end
private
# The config has information about how to construct the logger. If the config is invalid, and you want to know
@@ -136,65 +178,65 @@
# override raw.whatever.nested_value
ENV.each do |env_key, env_value|
next unless env_key.to_s.start_with?(CONTRAST_ENV_MARKER)
config_item = Contrast::Utils::EnvConfigurationItem.new(env_key, env_value)
- assign_value_to_path_array(root, config_item.dot_path_array, config_item.value)
+ assign_value_to_path_array(self, config_item.dot_path_array, config_item.value)
end
end
# Typically, the following values would be accessed through Contrast::Components::AppContext
# and Contrast::Components::API, but we're too early in the initialization of the Agent to use
# that mechanism, so we look it up directly for ourselves.
#
# @return [String, nil]
def api_url
- root.api.url
+ api.url
end
# Typically, the following values would be accessed through Contrast::Components::AppContext
# and Contrast::Components::API, but we're too early in the initialization of the Agent to use
# that mechanism, so we look it up directly for ourselves.
#
# @return [String, nil]
def api_key
- root.api.api_key
+ api.api_key
end
# Typically, the following values would be accessed through Contrast::Components::AppContext
# and Contrast::Components::API, but we're too early in the initialization of the Agent to use
# that mechanism, so we look it up directly for ourselves.
#
# @return [String, nil]
def api_service_key
- root.api.service_key
+ api.service_key
end
# Typically, the following values would be accessed through Contrast::Components::AppContext
# and Contrast::Components::API, but we're too early in the initialization of the Agent to use
# that mechanism, so we look it up directly for ourselves.
#
# @return [String, nil]
def api_username
- root.api.user_name
+ api.user_name
end
# Typically, the following values would be accessed through Contrast::Components::AppContext
# and Contrast::Components::API, but we're too early in the initialization of the Agent to use
# that mechanism, so we look it up directly for ourselves.
#
# @return [String, nil]
def bypass
- root.agent.service.bypass
+ agent.service.bypass
end
# Typically, the following values would be accessed through Contrast::Components::AppContext
# and Contrast::Components::Logger, but we're too early in the initialization of the Agent to use
# that mechanism, so we look it up directly for ourselves.
#
# @return [String, nil]
def logger_path
- root.agent.logger.path
+ agent.logger.path
end
# Assign the value from an ENV variable to the Contrast::Config::RootConfiguration object, when
# appropriate.
#