Sha256: 857b8b999b9928a48546f303023941f3b203a2b7469a514ba3ddecb5d9de0c74

Contents?: true

Size: 1.62 KB

Versions: 10

Compression:

Stored size: 1.62 KB

Contents

# Copyright (c) 2023 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 = Contrast::Utils::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

10 entries across 10 versions & 1 rubygems

Version Path
contrast-agent-7.6.1 lib/contrast/agent/deadzone/policy/policy.rb
contrast-agent-7.6.0 lib/contrast/agent/deadzone/policy/policy.rb
contrast-agent-7.5.0 lib/contrast/agent/deadzone/policy/policy.rb
contrast-agent-7.4.1 lib/contrast/agent/deadzone/policy/policy.rb
contrast-agent-7.4.0 lib/contrast/agent/deadzone/policy/policy.rb
contrast-agent-7.3.2 lib/contrast/agent/deadzone/policy/policy.rb
contrast-agent-7.3.1 lib/contrast/agent/deadzone/policy/policy.rb
contrast-agent-7.3.0 lib/contrast/agent/deadzone/policy/policy.rb
contrast-agent-7.2.0 lib/contrast/agent/deadzone/policy/policy.rb
contrast-agent-7.1.0 lib/contrast/agent/deadzone/policy/policy.rb