Class: Contrast::AgentLib::InterfaceBase

Inherits:
Object
  • Object
show all
Defined in:
lib/contrast/agent_lib/interface_base.rb

Overview

Base class to set basic rule sets and input list.

Direct Known Subclasses

Interface

Constant Summary collapse

LOG_LEVEL =
{ -1 => 'OFF', 0 => 'TRACE', 1 => 'DEBUG', 2 => 'INFO', 3 => 'WARN', 4 => 'ERROR' }.cs__freeze
LOG_DIR =
File.join(Dir.pwd).cs__freeze

Instance Method Summary collapse

Constructor Details

#initialize(enable_logging = nil, set_log_level = nil, set_log_dir = nil) ⇒ Boolean

Initializes the Agent lib.

likely to be a C segfaults and termination, probably redundant but safe.

Parameters:

  • enable_logging (Boolean, nil) (defaults to: nil)

    flag to enable or disable logging.

  • set_log_level (Integer, nil) (defaults to: nil)
  • set_log_dir (String, nil) (defaults to: nil)

    dir to write log files.

Raises:

  • (StandardError)

    Any Errors raised in the init process are most



23
24
25
# File 'lib/contrast/agent_lib/interface_base.rb', line 23

def initialize enable_logging = nil, set_log_level = nil, set_log_dir = nil
  # Override
end

Instance Method Details

#db_setHash

Return the AgentLib supported Database types.

Returns:



52
53
54
# File 'lib/contrast/agent_lib/interface_base.rb', line 52

def db_set
  @_db_set ||= extract_constants(ContrastAgentLib::DbType)
end

#eval_optionHash

Return list of input evaluation options: WorthWatching or none

Returns:



60
61
62
63
64
65
66
67
# File 'lib/contrast/agent_lib/interface_base.rb', line 60

def eval_option
  @_eval_option ||= begin
    consts = extract_constants(ContrastAgentLib::EvalOptions).dup
    # Adding the option to call the AgentLib without WorthWatching:
    consts[:NONE] = 0
    consts.cs__freeze
  end
end

#input_setHash

Returns list of available input types

Returns:



45
46
47
# File 'lib/contrast/agent_lib/interface_base.rb', line 45

def input_set
  @_input_set ||= extract_constants(ContrastAgentLib::InputType)
end

#rule_setHash

Return list of available rules. On first call the constants are extracted from the gem and set to resemble the protect rules ids used across the agent, e.g. CMD_INJECTIONS => cmd-injection.

*** Note that the NoSQLI rules is used within the agent, but in future need arise to be used with the AgentLib, the rule_id for that rule atm is ‘nosql-injection-mongo’ ***

All the rules types extracted from the AgentLib gem will have value corresponding to an ulong enum in Rust land. module name, or if module was renamed.

Returns:

Raises:

  • (NameError)

    If Gem is loaded but not constants are generated there could be not defined



38
39
40
# File 'lib/contrast/agent_lib/interface_base.rb', line 38

def rule_set
  @_rule_set ||= extract_constants(ContrastAgentLib::RuleType, to_rule_id: true)
end