Class: Contrast::Agent::Deadzone::Policy::Policy

Inherits:
Patching::Policy::Policy show all
Defined in:
lib/contrast/agent/deadzone/policy/policy.rb

Overview

This is just a holder for our policy. Takes the policy JSON and converts it into hashes that we can access nicely.

Constant Summary collapse

DEADZONES_KEY =
'deadzones'

Constants inherited from Patching::Policy::Policy

Patching::Policy::Policy::PROPAGATION_KEY, Patching::Policy::Policy::RULES_KEY, Patching::Policy::Policy::SOURCES_KEY, Patching::Policy::Policy::TRIGGERS_KEY

Instance Attribute Summary collapse

Attributes inherited from Patching::Policy::Policy

#propagators, #providers, #sources, #triggers

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Patching::Policy::Policy

#disabled_globally?, #find_node, #find_propagator_node, #find_source_node, #find_triggers_by_rule, policy_json

Methods included from Components::Logger::InstanceMethods

#cef_logger, #logger

Constructor Details

#initializePolicy

Returns a new instance of Policy.



21
22
23
24
# File 'lib/contrast/agent/deadzone/policy/policy.rb', line 21

def initialize
  @deadzones = []
  super
end

Instance Attribute Details

#deadzonesObject (readonly)

Returns the value of attribute deadzones.



19
20
21
# File 'lib/contrast/agent/deadzone/policy/policy.rb', line 19

def deadzones
  @deadzones
end

Class Method Details

.policy_folderObject



14
15
16
# File 'lib/contrast/agent/deadzone/policy/policy.rb', line 14

def self.policy_folder
  'deadzone'
end

Instance Method Details

#add_node(node, _node_type = :deadzones) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/contrast/agent/deadzone/policy/policy.rb', line 42

def add_node node, _node_type = :deadzones
  unless node
    logger.error('Node was nil when adding node to policy')
    return
  end

  begin
    node.validate
  rescue ArgumentError => e
    logger.error('Node failed validation', e)
    return
  end

  @deadzones << node
end

#from_hash_string(string) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/contrast/agent/deadzone/policy/policy.rb', line 30

def from_hash_string string
  policy_data = Contrast::Utils::Json.parse(string)

  policy_data[DEADZONES_KEY].each do |deadzone_hash|
    add_node(node_type.new(deadzone_hash))
  end
end

#module_namesObject



38
39
40
# File 'lib/contrast/agent/deadzone/policy/policy.rb', line 38

def module_names
  @_module_names ||= Set.new(deadzones.map(&:class_name))
end

#node_typeObject



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

def node_type
  Contrast::Agent::Deadzone::Policy::DeadzoneNode
end