Sha256: 1fc6950111cbd6f1ce597b1b5eadb13f7b4d4334b8138ff80cbc2fb7ad7b2404
Contents?: true
Size: 1.5 KB
Versions: 3
Compression:
Stored size: 1.5 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: Contrast::Utils::StringUtils.force_utf8(session_id) } end end end end end Contrast::Api::Settings::ApplicationSettings.include(Contrast::Api::Decorators::ApplicationSettings)
Version data entries
3 entries across 3 versions & 1 rubygems