lib/contrast/agent/reporting/reporting_events/preflight.rb in contrast-agent-6.11.0 vs lib/contrast/agent/reporting/reporting_events/preflight.rb in contrast-agent-6.12.0
- old
+ new
@@ -1,9 +1,10 @@
-# Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
+# 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
@@ -18,11 +19,11 @@
def initialize
@event_method = :PUT
@event_endpoint = "#{ Contrast::API.api_url }/api/ng/preflight/"
@messages = []
- super
+ super()
end
def file_name
'preflight'
end
@@ -31,10 +32,20 @@
# 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