Class: Contrast::Configuration

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Contrast::Components::Interface
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

DEFAULT_YAML_PATH =
'contrast_security.yaml'
MILLISECOND_MARKER =
'_ms'
CONVERSION =
{
    'agent.service.enable' => 'agent.start_bundled_service'
}.cs__freeze
CONFIG_BASE_PATHS =
[
  '',
  'config/',
  '/etc/contrast/ruby/',
  '/etc/contrast/',
  '/etc/'
].cs__freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Contrast::Components::Interface

included

Constructor Details

#initialize(cli_options = nil, default_name = DEFAULT_YAML_PATH) ⇒ Configuration

Returns a new instance of Configuration.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/contrast/configuration.rb', line 39

def initialize cli_options = nil, default_name = DEFAULT_YAML_PATH
  @default_name = default_name

  # Load config_kv from file
  config_kv = deep_stringify_all_keys(load_config)

  # Overlay CLI options - they take precedence over config file
  cli_options = deep_stringify_all_keys(cli_options)
  config_kv = deep_merge(cli_options, config_kv) if cli_options

  # Some in-flight rewrites to maintain backwards compatibility
  config_kv = update_prop_keys(config_kv)

  @root = Contrast::Config::RootConfiguration.new(config_kv)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *args) ⇒ Object

Because we call this method to determine the need for scoping, it itself must be executed inside a Contrast scope. Failure to do so could result in an infinite loop on the to_sym method used later.



58
59
60
61
62
63
64
# File 'lib/contrast/configuration.rb', line 58

def method_missing symbol, *args
  with_contrast_scope do
    root.public_send(symbol, *args)
  rescue NoMethodError => _e
    super
  end
end

Instance Attribute Details

#default_nameObject (readonly)

Returns the value of attribute default_name.



24
25
26
# File 'lib/contrast/configuration.rb', line 24

def default_name
  @default_name
end

#rootObject (readonly)

Returns the value of attribute root.



24
25
26
# File 'lib/contrast/configuration.rb', line 24

def root
  @root
end

Instance Method Details

#loggableString

Get a loggable YAML format of this configuration

Returns:

  • (String)

    the current active configuration of the Agent, represented as a YAML string



73
74
75
# File 'lib/contrast/configuration.rb', line 73

def loggable
  convert_to_hash.to_yaml
end

#respond_to_missing?(method_name, *args) ⇒ Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/contrast/configuration.rb', line 66

def respond_to_missing? method_name, *args
  root&.cs__respond_to?(method_name) || super
end