Sha256: 3bedc03127352a9cf570d3004de6d81b32bf2316a02ceafc88afd3c3f074b217
Contents?: true
Size: 1.94 KB
Versions: 5
Compression:
Stored size: 1.94 KB
Contents
# Copyright (c) 2023 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details. # frozen_string_literal: true require 'contrast/utils/timer' require 'contrast/agent/reporting/reporting_events/application_defend_attack_sample' require 'contrast/agent/reporting/reporting_events/reportable_hash' module Contrast module Agent module Reporting # This is the new AttackerSampleActivity class which will include Sample of the given attacks in the activity # period. class ApplicationDefendAttackSampleActivity < Contrast::Agent::Reporting::ReportableHash # @return [Array<Contrast::Agent::Reporting::ApplicationDefendAttackSample>] attr_reader :samples def initialize @samples = [] @start_time = Contrast::Agent::REQUEST_TRACKER.current&.timer&.start_ms || Contrast::Utils::Timer.now_ms @event_type = :application_defend_attack_sample_activity super() end def to_controlled_hash validate { samples: samples.map(&:to_controlled_hash), startTime: @start_time, # Start time in ms. total: 1 # there will only ever be 1 attack sample, until batching is done } end def validate raise(ArgumentError, 'Start Time is not presented') unless @start_time nil end # @param attack_result [Contrast::Agent::Reporting::AttackResult] def attach_data attack_result attack_result.samples.each do |attack_sample| samples << Contrast::Agent::Reporting::ApplicationDefendAttackSample.convert(attack_result, attack_sample) # If somehow this sample was found before this container was created, change the time to reflect that sample_time = attack_sample.time_stamp.to_i @start_time = sample_time if sample_time < @start_time end end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems