Sha256: 5013affb8f06d76b30b052d892ca6ae5f4e420962e95ddddcf0b19027d06362f

Contents?: true

Size: 1.6 KB

Versions: 7

Compression:

Stored size: 1.6 KB

Contents

# 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 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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
contrast-agent-4.11.0 lib/contrast/agent/deadzone/policy/policy.rb
contrast-agent-4.10.0 lib/contrast/agent/deadzone/policy/policy.rb
contrast-agent-4.9.1 lib/contrast/agent/deadzone/policy/policy.rb
contrast-agent-4.9.0 lib/contrast/agent/deadzone/policy/policy.rb
contrast-agent-4.8.0 lib/contrast/agent/deadzone/policy/policy.rb
contrast-agent-4.7.0 lib/contrast/agent/deadzone/policy/policy.rb
contrast-agent-4.6.0 lib/contrast/agent/deadzone/policy/policy.rb