Sha256: 1a1cf5b33317d0149755af60f901afba65b5e43d3da970282b8a457ed7e401e5

Contents?: true

Size: 1.53 KB

Versions: 2

Compression:

Stored size: 1.53 KB

Contents

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

require 'set'

module Contrast
  module Config
    # Common Configuration settings. Those in this section pertain to the
    # rule mode of a single protect rule in the Agent.
    class ProtectRuleConfiguration < BaseConfiguration
      KEYS = {
          enable: EMPTY_VALUE,
          mode: EMPTY_VALUE,
          disable_system_commands: EMPTY_VALUE,
          detect_custom_code_accessing_system_files: true
      }.cs__freeze

      def initialize hsh
        super(hsh, KEYS)
      end

      # To convert the user input mode from config to a standard format used by TS & SR, we need to convert the given
      # String to its Contrast::Api::Settings::ProtectionRule::Mode equivalent. If a nonsense value is provided, it'll
      # be treated the same as disabling the rule.
      #
      # @return [Contrast::Api::Settings::ProtectionRule::Mode, nil]
      def applicable_mode
        return unless mode

        case mode
        when 'permit'
          Contrast::Api::Settings::ProtectionRule::Mode::PERMIT
        when 'block_at_perimeter'
          Contrast::Api::Settings::ProtectionRule::Mode::BLOCK_AT_PERIMETER
        when 'block'
          Contrast::Api::Settings::ProtectionRule::Mode::BLOCK
        when 'monitor'
          Contrast::Api::Settings::ProtectionRule::Mode::MONITOR
        else
          Contrast::Api::Settings::ProtectionRule::Mode::NO_ACTION
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
contrast-agent-5.1.0 lib/contrast/config/protect_rule_configuration.rb
contrast-agent-5.0.0 lib/contrast/config/protect_rule_configuration.rb