lib/contrast/components/config.rb in contrast-agent-3.16.0 vs lib/contrast/components/config.rb in contrast-agent-4.0.0
- old
+ new
@@ -1,11 +1,9 @@
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
# frozen_string_literal: true
-require 'contrast/utils/boolean_util'
require 'contrast/utils/env_configuration_item'
-require 'contrast/utils/object_share'
require 'contrast/configuration'
module Contrast
module Components
# This component encapsulates reference to the configuration file.
@@ -37,55 +35,27 @@
env_overrides
validate(log: log)
end
alias_method :rebuild, :build
- # Prefer abstraction, but use #raw if you need.
- # grep 'CONFIG.raw' for opportunities to refactor.
- def raw
- @config
- end
-
+ # @return [Contrast::Config::RootConfiguration]
def root
- raw.root
+ @config.root
end
- def enabled?
- @_enabled = !Contrast::Utils::BooleanUtil.false?(raw.enable) if @_enabled.nil?
- @_enabled
- end
-
- def disabled?
- !enabled?
- end
-
- def protect?
- @_protect = Contrast::Utils::BooleanUtil.true?(raw.protect.enable) if @_protect.nil?
- @_protect
- end
-
- def assess?
- @_assess = Contrast::Utils::BooleanUtil.true?(raw.assess.enable) if @_assess.nil?
- @_assess
- end
-
- def session_id
- @_session_id ||= raw.application.session_id
- end
-
- def session_metadata
- @_session_metadata ||= raw.application.session_metadata
- end
-
def valid?
@_valid = validate(log: false) if @_valid.nil?
end
def invalid?
!valid?
end
+ def loggable
+ @config.loggable
+ end
+
private
SESSION_VARIABLES = "Invalid configuration. Setting both application.session_id and application.session_metadata is not allowed.\n"
def validate log: false
# The config has information about how to construct the logger.
@@ -109,11 +79,33 @@
# 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)
- raw.assign_value_to_path_array(config_item.dot_path_array, config_item.value)
+ @config.assign_value_to_path_array(config_item.dot_path_array, config_item.value)
end
+ end
+
+ # Typically, this would be accessed through
+ # Contrast::Components::AppContext, 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] the value of the session id set in the
+ # configuration, or nil if unset
+ def session_id
+ @config.application.session_id
+ end
+
+ # Typically, this would be accessed through
+ # Contrast::Components::AppContext, 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] the value of the session metadata set in the
+ # configuration, or nil if unset
+ def session_metadata
+ @config.application.session_metadata
end
end
COMPONENT_INTERFACE = Interface.new
end