# Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details. # frozen_string_literal: true module Contrast module Agent module Reporting # This module will hold the methods for TS response conversion to settings objects. module ResponseExtractor private # @param response_data [Hash] # @param res [Contrast::Agent::Reporting::Response] def extract_assess response_data, res assessments = response_data[:settings][:assessment] return unless assessments res.application_settings.assess.disabled_rules = assessments[:disabledRules] res.application_settings.assess.session_id = assessments[:sessionId] end # @param response_data [Hash] # @param res [Contrast::Agent::Reporting::Response] def extract_protect response_data, res protect = response_data[:settings][:defend] return unless protect res.application_settings.protect.protection_rules = protect[:protectionRules] res.application_settings.protect.virtual_patches = protect[:virtualPatches] end # @param response_data [Hash] # @param res [Contrast::Agent::Reporting::Response] def extract_exclusions response_data, res exclusions = response_data[:settings][:exceptions] return unless exclusions res.application_settings.exclusions.code_exclusions = exclusions[:codeExceptions] res.application_settings.exclusions.input_exclusions = exclusions[:inputExceptions] res.application_settings.exclusions.url_exclusions = exclusions[:urlExceptions] end # @param response_data [Hash] # @param res [Contrast::Agent::Reporting::Response] def extract_reactions response_data, res res.application_settings.reactions = response_data[:settings][:reactions] end # @param response_data [Hash] # @param res [Contrast::Agent::Reporting::Response] def extract_assess_server_features response_data, res assess = response_data[:assessment] return unless assess res.server_features.assess.enabled = assess[:enabled] res.server_features.assess.sampling = assess[:sampling] res.server_features.assess.sanitizers = assess[:sanitizers] res.server_features.assess.validators = assess[:validators] end # @param response_data [Hash] # @param res [Contrast::Agent::Reporting::Response] def extract_protect_server_features response_data, res protect = response_data[:defend] return unless protect res.server_features.protect.enabled = protect[:enabled] res.server_features.protect.bot_blocker = protect[:bot_blocker] res.server_features.protect.syslog = protect[:syslog] end # @param response_data [Hash] # @param res [Contrast::Agent::Reporting::Response] def extract_protect_lists response_data, res protect = response_data[:defend] return unless protect res.server_features.protect.ip_allowlist = protect[:ipAllowlist] res.server_features.protect.ip_denylist = protect[:ipDenyList] res.server_features.protect.log_enchancers = protect[:logEnhancers] res.server_features.protect.rule_definition_list = protect[:ruleDefinitionList] end # Here we extract the rules and state for the sensitive data masking policy # Received from TS. # # @param response_data [Hash] # @param res [Contrast::Agent::Reporting::Response] def extract_sensitive_data_policy response_data, res sensitive_data = response_data[:settings][:sensitive_data_masking_policy] res.application_settings.sensitive_data_masking.mask_http_body = sensitive_data[:mask_http_body] res.application_settings.sensitive_data_masking.mask_attack_vector = sensitive_data[:mask_attack_vector] res.application_settings.sensitive_data_masking.build_rules_form_settings sensitive_data[:rules] end end end end end