# Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details. # frozen_string_literal: true require 'contrast/agent/deadzone/policy/deadzone_node' require 'contrast/agent/patching/policy/policy' module Contrast module Agent module Deadzone module Policy # This is just a holder for our policy. Takes the policy JSON and converts it into hashes that we can access # nicely. class Policy < Contrast::Agent::Patching::Policy::Policy def self.policy_folder 'deadzone' end DEADZONES_KEY = 'deadzones' attr_reader :deadzones def initialize @deadzones = [] super end def node_type Contrast::Agent::Deadzone::Policy::DeadzoneNode end def from_hash_string string policy_data = JSON.parse(string) policy_data[DEADZONES_KEY].each do |deadzone_hash| add_node(node_type.new(deadzone_hash)) end end def validate return if class_name raise(ArgumentError, "#{ node_class } #{ id } did not have a proper class name. Unable to create.") end def module_names @_module_names ||= Set.new(deadzones.map(&:class_name)) end 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 end end end end end