# 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 REPORT_STACKTRACES = %w[ALL SOME NONE].cs__freeze # 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 end # @return [String] ALL, SOME, NONE def report_stacktraces @_report_stacktraces end # @return [String] ALL, SOME, NONE def report_stacktraces= level @_report_stacktraces = level if REPORT_STACKTRACES.include?(level) 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] 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] def sanitizers @_sanitizers ||= [] end # set sanitizer # # @param sanitizers_array [Array] # @return sanitizers [Array] 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] def validators @_validators ||= [] end # set validators # # @param validators_array [Array] # @return sanitizers [Array] 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, report_stacktraces: report_stacktraces, # used with ServerSettings only sanitizers: sanitizers.map(&:to_controlled_hash), validators: validators.map(&:to_controlled_hash) }.compact end end end end end end