Sha256: 9f998fb64a38531ccc6184102a27c6d0ac2318c9cb26b63b986b2d1c1d1111a9

Contents?: true

Size: 1.52 KB

Versions: 7

Compression:

Stored size: 1.52 KB

Contents

# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
# frozen_string_literal: true

cs__scoped_require 'contrast/agent/deadzone/policy/deadzone_node'
cs__scoped_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 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-3.13.2 lib/contrast/agent/deadzone/policy/policy.rb
contrast-agent-3.13.1 lib/contrast/agent/deadzone/policy/policy.rb
contrast-agent-3.13.0 lib/contrast/agent/deadzone/policy/policy.rb
contrast-agent-3.12.2 lib/contrast/agent/deadzone/policy/policy.rb
contrast-agent-3.12.1 lib/contrast/agent/deadzone/policy/policy.rb
contrast-agent-3.12.0 lib/contrast/agent/deadzone/policy/policy.rb
contrast-agent-3.11.0 lib/contrast/agent/deadzone/policy/policy.rb