# Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details. # frozen_string_literal: true require 'contrast/utils/object_share' require 'contrast/agent/reporting/settings/sampling' require 'contrast/agent/reporting/settings/sanitizer' require 'contrast/agent/reporting/settings/validator' require 'contrast/agent/reporting/settings/helpers' module Contrast module Agent module Reporting # This module will hold all the settings from the TS responce module Settings # Application level settings for the Assess featureset. # Used for the FeatureSet TS response class AssessServerFeature # Indicate if the assess feature set is enabled for this server or not. # # @return enabled [Boolean] def enabled? @_enabled end # Set the enabled # # @param enabled [Boolean] # @return enabled [Boolean] def enabled= enabled @_enabled = enabled if !!enabled == enabled end # Used to control the sampling feature in the agent. # # @return [Contrast::Agent::Reporting::Settings::Sampling] def sampling @_sampling ||= Contrast::Agent::Reporting::Settings::Sampling.new({}) end # set sampling # # @param sampling [Hash<AssessSampling>] Hash of AssessSampling: { # baseline [Integer] The number of baseline requests to take before switching to sampling # for the window. # enabled [Boolean] If the sampling feature should be used or not. # frequency [Integer] The number of requests to skip before observing during the sampling # window after the baseline. # responseFrequency [Integer] # window [Integer] # } # @return [Contrast::Agent::Reporting::Settings::Sampling] def sampling= sampling @_sampling = Contrast::Agent::Reporting::Settings::Sampling.new(sampling) if sampling.is_a?(Hash) end # The sanitizers defined by the user for use by the agent on this server for this organization. # # @return sanitizers [Array<Contrast::Agent::Reporting::Settings::Sanitizer>] def sanitizers @_sanitizers ||= [] end # set sanitizer # # @param sanitizers_array [Array<Contrast::Agent::Reporting::Settings::Sanitizer>] # @return sanitizers [Array<Contrast::Agent::Reporting::Settings::Sanitizer>] def sanitizers= sanitizers_array Contrast::Agent::Reporting::Settings::Helpers.array_to_iv(Contrast::Agent::Reporting::Settings::Sanitizer, sanitizers, sanitizers_array) end # The validators defined by the user for use by the agent on this server for this organization. # # @return sanitizers [Array<Contrast::Agent::Reporting::Settings::Validator>] def validators @_validators ||= [] end # set validators # # @param validators_array [Array<Contrast::Agent::Reporting::Settings::Validator>] # @return sanitizers [Array<Contrast::Agent::Reporting::Settings::Validator>] def validators= validators_array Contrast::Agent::Reporting::Settings::Helpers.array_to_iv(Contrast::Agent::Reporting::Settings::Validator, validators, validators_array) end def to_controlled_hash { enabled: enabled?, sampling: sampling.to_controlled_hash, sanitizers: sanitizers.map(&:to_controlled_hash), validators: validators.map(&:to_controlled_hash) } end end end end end end