# Copyright (c) 2023 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details. # frozen_string_literal: true require 'base64' require 'contrast/agent/reporting/reporting_events/reportable_hash' require 'contrast/utils/duck_utils' module Contrast module Agent module Reporting # This is the new FindingEventSource class which will include all the needed information for the new reporting # system to relay this information in the Finding/Trace messages. These FindingEventSource are used by TeamServer # to construct the vulnerability information for the assess feature. They indicate the type of data that the # event represents. class FindingEventSource < Contrast::Agent::Reporting::ReportableHash # @return [String] the name of the source attr_reader :source_name # @return [String] the type of the source attr_reader :source_type # @param type [String] # @param name [String] def initialize type, name @source_type = type @source_name = name super() end # Convert the instance variables on the class, and other information, into the identifiers required for # TeamServer to process the JSON form of this message. # # @return [Hash] # @raise [ArgumentError] def to_controlled_hash validate { sourceName: source_name, sourceType: source_type } end # Convert this EventSource into the format expected for route observation # # @return [Hash] # @raise [ArgumentError] def to_controlled_observation_hash validate { name: source_name, type: source_type } end # @raise [ArgumentError] def validate return unless Contrast::Utils::DuckUtils.empty_duck?(source_type) raise(ArgumentError, "#{ self } did not have a proper type. Unable to continue.") end end end end end