lib/contrast/components/settings.rb in contrast-agent-4.14.1 vs lib/contrast/components/settings.rb in contrast-agent-5.0.0

- old
+ new

@@ -1,6 +1,6 @@ -# Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details. +# Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details. # frozen_string_literal: true require 'contrast/api/settings.pb' module Contrast @@ -34,22 +34,35 @@ def code_exclusions @application_state.exclusion_matchers.select(&:code?) end - # @param server_features [Contrast::Api::Settings::ServerFeatures] - def update_from_server_features server_features - @protect_state.enabled = server_features.protect_enabled? - @assess_state.enabled = server_features.assess_enabled? - @assess_state.sampling_settings = server_features.assess.sampling + # @param features [Contrast::Api::Settings::ServerFeatures, Contrast::Agent::Reporting::Response] + def update_from_server_features features + if features&.class == Contrast::Agent::Reporting::Response + @protect_state.enabled = features.server_features.protect.enabled? + @assess_state.enabled = features.server_features.assess.enabled? + @assess_state.sampling_settings = features.server_features.assess.sampling + else + @protect_state.enabled = features.protect_enabled? + @assess_state.enabled = features.assess_enabled? + @assess_state.sampling_settings = features.assess.sampling + end end - # @param application_settings [Contrast::Api::Settings::ApplicationSettings] - def update_from_application_settings application_settings - new_vals = application_settings.application_state_translation - @application_state.modes_by_id = new_vals[:modes_by_id] - @application_state.exclusion_matchers = new_vals[:exclusion_matchers] - @assess_state.disabled_assess_rules = new_vals[:disabled_assess_rules] + # @param features [Contrast::Api::Settings::ApplicationSettings, Contrast::Agent::Reporting::Response] + def update_from_application_settings features + if features&.class == Contrast::Agent::Reporting::Response + @application_state.modes_by_id = features.application_settings.protect.protection_rules_to_settings_hash + # TODO: RUBY-1438 this needs to be translated + # @application_state.exclusion_matchers = new_vals[:exclusion_matchers] + @assess_state.disabled_assess_rules = features.application_settings.assess.disabled_rules + else + new_vals = features.application_state_translation + @application_state.modes_by_id = new_vals[:modes_by_id] + @application_state.exclusion_matchers = new_vals[:exclusion_matchers] + @assess_state.disabled_assess_rules = new_vals[:disabled_assess_rules] + end end # Wipe state to zero. def reset_state @protect_state = PROTECT_STATE_BASE.dup