Sha256: 0871960e0ce90ff54b1e5b8b7d84aa32554f41b36037d87bea8c9c3730db7f15

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 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/utils/string_utils'

module Contrast
  module Api
    module Decorators
      # Used to decorate the ApplicationSettings protobuf model to handle setting translation
      module ApplicationSettings
        MODE_ALLOWLIST = %i[NO_ACTION BLOCK_AT_PERIMETER MONITOR BLOCK].cs__freeze
        # Convert protobuf exlcusions into Agent exclusions
        def translated_exclusions
          exclusions.map { |exc| Contrast::Agent::ExclusionMatcher.new(exc) }
        end

        # Convert protobuf protect rule settings into a hash that settings state understands
        def translated_protection_mode_by_id
          protection_rules = self.protection_rules.map { |pr, _hash| [pr.id, pr.mode] } # [[RULE_ID, MODE]]
          protection_rules.select! { |(_id, mode)| MODE_ALLOWLIST.include? mode } # [REMOVE IF MODE INVALID]
          protection_rules.to_h # {RULE_ID => MODE}
        end

        def application_state_translation
          {
              modes_by_id: translated_protection_mode_by_id,
              exclusion_matchers: translated_exclusions,
              disabled_assess_rules: disabled_assess_rules,
              session_id: session_id
          }
        end
      end
    end
  end
end

Contrast::Api::Settings::ApplicationSettings.include(Contrast::Api::Decorators::ApplicationSettings)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
contrast-agent-3.11.0 lib/contrast/api/decorators/application_settings.rb