Sha256: b9bb335fb6c36f2eaba97169834f1a92b4b6a6361095756ab10cf9a11b8b4a9b

Contents?: true

Size: 1.85 KB

Versions: 5

Compression:

Stored size: 1.85 KB

Contents

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

require 'contrast/agent/patching/policy/policy_node'
require 'contrast/utils/object_share'

module Contrast
  module Agent
    module Assess
      module Policy
        # This module will extend the PolicyNode, which functions is to translate
        # our policy.json into an actionable Ruby object, allowing for dynamic
        # patching over hardcoded patching.
        module PolicyNodeUtils
          private

          # Given a policy string in the format A,B,C, populate the given array
          # 1) Split on ','
          # 2) If 'O' or 'R', add the array, else it's P and needs to be
          #    converted. P type will either be P# where # is the index
          #    of the parameter. Drop the P and store the # as an int.
          #
          # @param markers [String] the String from the policy to parse
          # @return [Array] the array generated by converting the marker string
          def convert_policy_markers markers
            return Contrast::Utils::ObjectShare::EMPTY_ARRAY unless markers
            return Contrast::Utils::ObjectShare::EMPTY_ARRAY if markers.empty?

            converted = []
            markers.split(Contrast::Utils::ObjectShare::COMMA).each do |maker|
              converted << case maker
                           when Contrast::Utils::ObjectShare::OBJECT_KEY,
                             Contrast::Utils::ObjectShare::RETURN_KEY

                             maker
                           else
                             Integer(maker[1..])
                           end
            end
            converted
          end

          def all_type? marker
            marker.include?(Contrast::Utils::ObjectShare::COMMA)
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
contrast-agent-6.11.0 lib/contrast/agent/assess/policy/policy_node_utils.rb
contrast-agent-6.10.0 lib/contrast/agent/assess/policy/policy_node_utils.rb
contrast-agent-6.9.0 lib/contrast/agent/assess/policy/policy_node_utils.rb
contrast-agent-6.8.0 lib/contrast/agent/assess/policy/policy_node_utils.rb
contrast-agent-6.7.0 lib/contrast/agent/assess/policy/policy_node_utils.rb