Class: Contrast::Components::Config::Interface

Inherits:
Object
  • Object
show all
Defined in:
lib/contrast/components/config.rb

Overview

:nodoc: # rubocop:disable Metrics/ClassLength

Constant Summary collapse

SESSION_VARIABLES =
'Invalid configuration. ' \
"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."

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeInterface

Returns a new instance of Interface.



41
42
43
# File 'lib/contrast/components/config.rb', line 41

def initialize
  build
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



39
40
41
# File 'lib/contrast/components/config.rb', line 39

def config
  @config
end

Instance Method Details

#agentContrast::Components::Agent::Interface



75
76
77
# File 'lib/contrast/components/config.rb', line 75

def agent
  @config.agent
end

#apiContrast::Components::Api::Interface



70
71
72
# File 'lib/contrast/components/config.rb', line 70

def api
  @config.api
end

#applicationContrast::Components::AppContext::Interface



80
81
82
# File 'lib/contrast/components/config.rb', line 80

def application
  @config.application
end

#assessContrast::Components::Assess::Interface



90
91
92
# File 'lib/contrast/components/config.rb', line 90

def assess
  @config.assess
end

#buildObject Also known as: rebuild



59
60
61
62
63
64
65
66
# File 'lib/contrast/components/config.rb', line 59

def build
  @_valid = nil
  @config = Contrast::Configuration.new
  env_overrides
  validate
rescue ArgumentError => e
  proto_logger.error('[PROTO_LOGGER] Configuration failed with error: ', e)
end

#config_file_pathString?

Returns the path to the YAML config file, if any.

Returns:

  • (String, nil)

    the path to the YAML config file, if any.



139
140
141
# File 'lib/contrast/components/config.rb', line 139

def config_file_path
  config.config_file
end

#enableObject



109
110
111
# File 'lib/contrast/components/config.rb', line 109

def enable
  @config.enable
end

#invalid?Boolean

Returns:

  • (Boolean)


117
118
119
# File 'lib/contrast/components/config.rb', line 117

def invalid?
  !valid?
end

#inventoryContrast::Components::Inventory::Interface



95
96
97
# File 'lib/contrast/components/config.rb', line 95

def inventory
  @config.inventory
end

#loggableObject



121
122
123
# File 'lib/contrast/components/config.rb', line 121

def loggable
  @config.loggable
end

#protectContrast::Components::Protect::Interface



100
101
102
# File 'lib/contrast/components/config.rb', line 100

def protect
  @config.protect
end

#proto_loggerObject

Basic logger for handling configuration validation logging the file to log is determined by the default one or set by the config file, if that configuration is found



48
49
50
51
52
53
54
55
56
57
# File 'lib/contrast/components/config.rb', line 48

def proto_logger
  @_proto_logger ||= begin
    @_proto_logger = ::Ougai::Logger.new(logger_path || CONTRAST_LOG)
    @_proto_logger.progname = CONTRAST_NAME
    @_proto_logger.level = ::Ougai::Logging::Severity::WARN
    @_proto_logger.formatter = Contrast::Logger::Format.new
    @_proto_logger.formatter.datetime_format = DATE_TIME
    @_proto_logger
  end
end

#serverContrast::Config::ServerConfiguration



85
86
87
# File 'lib/contrast/components/config.rb', line 85

def server
  @config.server
end

#session_idString?

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.

Returns:

  • (String, nil)

    the value of the session id set in the configuration, or nil if unset



129
130
131
# File 'lib/contrast/components/config.rb', line 129

def session_id
  application.session_id
end

#session_metadataString?

Returns the value of the session metadata set in the configuration, or nil if unset.

Returns:

  • (String, nil)

    the value of the session metadata set in the configuration, or nil if unset



134
135
136
# File 'lib/contrast/components/config.rb', line 134

def 
  application.
end

#sourcesObject



113
114
115
# File 'lib/contrast/components/config.rb', line 113

def sources
  @config.sources
end

#valid?Boolean

Returns:

  • (Boolean)


104
105
106
107
# File 'lib/contrast/components/config.rb', line 104

def valid?
  @_valid = validate if @_valid.nil?
  @_valid
end