Module: Contrast::Api::Decorators::ApplicationSettings

Included in:
Settings::ApplicationSettings
Defined in:
lib/contrast/api/decorators/application_settings.rb

Overview

Used to decorate the Settings::ApplicationSettings protobuf model to handle setting translation.

Constant Summary collapse

MODE_ALLOWLIST =
[
  Contrast::Api::Settings::ProtectionRule::Mode::NO_ACTION,
  Contrast::Api::Settings::ProtectionRule::Mode::BLOCK,
  Contrast::Api::Settings::ProtectionRule::Mode::MONITOR,
  Contrast::Api::Settings::ProtectionRule::Mode::BLOCK_AT_PERIMETER
].cs__freeze

Instance Method Summary collapse

Instance Method Details

#application_state_translationObject



30
31
32
33
34
35
36
# File 'lib/contrast/api/decorators/application_settings.rb', line 30

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

#translated_exclusionsObject

Convert protobuf exlcusions into Agent exclusions



19
20
21
# File 'lib/contrast/api/decorators/application_settings.rb', line 19

def translated_exclusions
  exclusions.map { |exc| Contrast::Agent::ExclusionMatcher.new(exc) }
end

#translated_protection_mode_by_idObject

Convert protobuf protect rule settings into a hash that settings state understands



24
25
26
27
28
# File 'lib/contrast/api/decorators/application_settings.rb', line 24

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