# Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details. # frozen_string_literal: true require 'contrast/agent/reporting/reporting_events/preflight_message' require 'contrast/agent/reporting/reporting_events/preflight' require 'contrast/agent/reporting/reporting_events/route_discovery' require 'contrast/agent/reporting/reporting_utilities/reporting_storage' module Contrast module Agent module Reporting # This module will handle the building of new preflights prior to # sending them. module BuildPreflight class << self # @param finding [Contrast::Agent::Reporting::Finding] # @param request [Contrast::Agent::Request] current request def build finding, request return unless finding # save the current finding Contrast::Agent::Reporting::ReportingStorage[finding.hash_code] = finding new_preflight = Contrast::Agent::Reporting::Preflight.new new_preflight_message = Contrast::Agent::Reporting::PreflightMessage.new if request&.route new_preflight_message.routes << Contrast::Agent::Reporting::RouteDiscovery.convert(request.route) end new_preflight_message.hash_code = finding.hash_code new_preflight_message.data = "#{ finding.rule_id },#{ finding.hash_code }" new_preflight.messages << new_preflight_message new_preflight end end end end end end