Class: Contrast::Components::Agent::Interface

Inherits:
Object
  • Object
show all
Includes:
ComponentBase
Defined in:
lib/contrast/components/agent.rb

Overview

A wrapper build around the Common Agent Configuration project to allow for access of the values contained in its parent_configuration_spec.yaml. Specifically, this allows for querying the state of the Agent.

Constant Summary collapse

CANON_NAME =
'agent'
CONFIG_VALUES =
%w[enabled? omit_body?].cs__freeze

Constants included from ComponentBase

ComponentBase::ENABLE

Constants included from Contrast::Config::Diagnostics::Tools

Contrast::Config::Diagnostics::Tools::CHECK

Constants included from Contrast::Config::Diagnostics::SingletonTools

Contrast::Config::Diagnostics::SingletonTools::API_CREDENTIALS, Contrast::Config::Diagnostics::SingletonTools::CONTRAST_MARK

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ComponentBase

#false?, #file_exists?, #stringify_array, #true?, #valid_cert?

Methods included from Contrast::Config::Diagnostics::Tools

#add_effective_config_values, #add_single_effective_value

Methods included from Contrast::Config::Diagnostics::SingletonTools

#flatten_settings, #to_config_values, #update_config, #value_to_s

Constructor Details

#initialize(hsh = {}) ⇒ Interface

Returns a new instance of Interface.



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/contrast/components/agent.rb', line 35

def initialize hsh = {}
  @config_values = CONFIG_VALUES
  @canon_name = CANON_NAME
  return unless hsh

  @_enable = hsh[:enable]
  @_omit_body = hsh[:omit_body]
  @_polling = Contrast::Components::Polling::Interface.new(hsh[:polling])
  @_logger = Contrast::Components::Logger::Interface.new(hsh[:logger])
  @_security_logger = Contrast::Components::SecurityLogger::Interface.new(hsh[:security_logger])
  @_ruby = Contrast::Components::Ruby::Interface.new(hsh[:ruby])
  @_heap_dump = Contrast::Components::HeapDump::Interface.new(hsh[:heap_dump])
end

Instance Attribute Details

#canon_nameString (readonly)

Returns:



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

def canon_name
  @canon_name
end

#config_valuesArray (readonly)

Returns:

  • (Array)


26
27
28
# File 'lib/contrast/components/agent.rb', line 26

def config_values
  @config_values
end

#enableBoolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/contrast/components/agent.rb', line 28

def enable
  @enable
end

#omit_bodyBoolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/contrast/components/agent.rb', line 30

def omit_body
  @omit_body
end

Instance Method Details

#disable!Object



90
91
92
93
94
# File 'lib/contrast/components/agent.rb', line 90

def disable!
  @_enable = false
  Contrast::Agent::TracePointHook.disable
  Contrast::Agent.thread_watcher&.shutdown!
end

#disable_agent!Object



108
109
110
# File 'lib/contrast/components/agent.rb', line 108

def disable_agent!
  @_enable = false
end

#disabled?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/contrast/components/agent.rb', line 82

def disabled?
  !enabled?
end

#enable!Object



86
87
88
# File 'lib/contrast/components/agent.rb', line 86

def enable!
  @_enable = true
end

#enable_tracepointObject



131
132
133
# File 'lib/contrast/components/agent.rb', line 131

def enable_tracepoint
  Contrast::Agent::TracePointHook.enable!
end

#enabled?Boolean

Returns:

  • (Boolean)


77
78
79
80
# File 'lib/contrast/components/agent.rb', line 77

def enabled?
  @_enable = !false?(::Contrast::CONFIG.enable) if @_enable.nil?
  @_enable
end

#exception_controlObject



112
113
114
115
116
117
118
# File 'lib/contrast/components/agent.rb', line 112

def exception_control
  @_exception_control ||= {
      enable: true?(ruby.exceptions.capture),
      status: ruby.exceptions.override_status || 403,
      message: ruby.exceptions.override_message || Contrast::Utils::ObjectShare::OVERRIDE_MESSAGE
  }
end

#heap_dumpObject



71
72
73
74
75
# File 'lib/contrast/components/agent.rb', line 71

def heap_dump
  return @_heap_dump unless @_heap_dump.nil?

  @_heap_dump = Contrast::Components::HeapDump::Interface.new
end

#insert_middleware(app) ⇒ Object

Insert ourselves into the application, keeping our middleware at the outermost layer of the onion



127
128
129
# File 'lib/contrast/components/agent.rb', line 127

def insert_middleware app
  app.middleware.insert_before(0, Contrast::Agent::Middleware)
end

#loggerObject



49
50
51
52
53
# File 'lib/contrast/components/agent.rb', line 49

def logger
  return @_logger unless @_logger.nil?

  @_logger = Contrast::Components::Logger::Interface.new
end

#omit_body?Boolean

Returns:

  • (Boolean)


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

def omit_body?
  true?(@_omit_body)
end

#patch_yield?Boolean

Returns:

  • (Boolean)


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

def patch_yield?
  !false?(ruby.propagate_yield)
end

#pollingObject



55
56
57
# File 'lib/contrast/components/agent.rb', line 55

def polling
  @_polling ||= Contrast::Components::Polling::Interface.new
end

#rubyObject



65
66
67
68
69
# File 'lib/contrast/components/agent.rb', line 65

def ruby
  return @_ruby unless @_ruby.nil?

  @_ruby = Contrast::Components::Ruby::Interface.new
end

#rulesetObject



96
97
98
# File 'lib/contrast/components/agent.rb', line 96

def ruleset
  @_ruleset ||= Contrast::Agent::RuleSet.new(retrieve_protect_ruleset.values)
end

#security_loggerObject



59
60
61
62
63
# File 'lib/contrast/components/agent.rb', line 59

def security_logger
  return @_security_logger unless @_security_logger.nil?

  @_security_logger = Contrast::Components::SecurityLogger::Interface.new
end

#skip_instrumentation?(loaded_module_name) ⇒ Boolean

Returns:

  • (Boolean)


120
121
122
123
124
# File 'lib/contrast/components/agent.rb', line 120

def skip_instrumentation? loaded_module_name
  return true unless loaded_module_name

  loaded_module_name.start_with?(*::Contrast::CONFIG.agent.ruby.uninstrument_namespace)
end

#to_effective_config(effective_config) ⇒ Object

Converts current configuration to effective config values class and appends them to EffectiveConfig class.

Parameters:



139
140
141
142
143
144
145
146
# File 'lib/contrast/components/agent.rb', line 139

def to_effective_config effective_config
  super
  logger&.to_effective_config(effective_config)
  security_logger&.to_effective_config(effective_config)
  ruby&.to_effective_config(effective_config)
  heap_dump&.to_effective_config(effective_config)
  polling&.to_effective_config(effective_config)
end