Sha256: 0d19029150bbfe21b013571dd3eb3f6808f0fa18d8f972de1d294063b7b9fd27

Contents?: true

Size: 1.9 KB

Versions: 18

Compression:

Stored size: 1.9 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/agent/reporting/reporting_events/application_reporting_event'
require 'contrast/utils/duck_utils'

module Contrast
  module Agent
    module Reporting
      # This is the new Preflight class which will include all the needed information for the new reporting system
      # to report a Preflight message to TeamServer. This message represents the identifying information of a
      # collection of Findings/Traces, which TeamServer will use to determine if it requires the full information of
      # any of the Findings/Traces to be reported.
      class Preflight < Contrast::Agent::Reporting::ApplicationReportingEvent
        # For our purposes, we'll only ever send one message per request; however,
        # we must use an array to conform to the specification.
        # @return messages [Array<Contrast::Agent::Reporting::PreflightMessage>]
        attr_reader :messages

        def initialize
          @event_method = :PUT
          @event_endpoint = "#{ Contrast::API.api_url }/api/ng/preflight/"
          @messages = []
          super()
        end

        def file_name
          'preflight'
        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
          { messages: @messages.map(&:to_controlled_hash) }
        end

        # @raise [ArgumentError]
        def validate
          if Contrast::Utils::DuckUtils.empty_duck?(messages)
            raise(ArgumentError, "#{ cs__class } did not have any messages. Unable to continue.")
          end

          nil
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
contrast-agent-7.6.1 lib/contrast/agent/reporting/reporting_events/preflight.rb
contrast-agent-7.6.0 lib/contrast/agent/reporting/reporting_events/preflight.rb
contrast-agent-7.5.0 lib/contrast/agent/reporting/reporting_events/preflight.rb
contrast-agent-7.4.1 lib/contrast/agent/reporting/reporting_events/preflight.rb
contrast-agent-7.4.0 lib/contrast/agent/reporting/reporting_events/preflight.rb
contrast-agent-7.3.2 lib/contrast/agent/reporting/reporting_events/preflight.rb
contrast-agent-7.3.1 lib/contrast/agent/reporting/reporting_events/preflight.rb
contrast-agent-7.3.0 lib/contrast/agent/reporting/reporting_events/preflight.rb
contrast-agent-7.2.0 lib/contrast/agent/reporting/reporting_events/preflight.rb
contrast-agent-7.1.0 lib/contrast/agent/reporting/reporting_events/preflight.rb
contrast-agent-7.0.0 lib/contrast/agent/reporting/reporting_events/preflight.rb
contrast-agent-6.15.3 lib/contrast/agent/reporting/reporting_events/preflight.rb
contrast-agent-6.15.2 lib/contrast/agent/reporting/reporting_events/preflight.rb
contrast-agent-6.15.1 lib/contrast/agent/reporting/reporting_events/preflight.rb
contrast-agent-6.15.0 lib/contrast/agent/reporting/reporting_events/preflight.rb
contrast-agent-6.14.0 lib/contrast/agent/reporting/reporting_events/preflight.rb
contrast-agent-6.13.0 lib/contrast/agent/reporting/reporting_events/preflight.rb
contrast-agent-6.12.0 lib/contrast/agent/reporting/reporting_events/preflight.rb