Sha256: 5076da3d5a7e73bbe911d66ef5f15671664c89bed632547a0286bad5a2da3c1f

Contents?: true

Size: 1.59 KB

Versions: 4

Compression:

Stored size: 1.59 KB

Contents

# Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
# frozen_string_literal: true

require 'contrast/components/logger'
require 'contrast/agent/reporting/reporting_events/reporting_event'
require 'contrast/agent/reporting/reporting_events/discovered_route'

module Contrast
  module Agent
    module Reporting
      # This is the new ApplicationInventory class which will include all the needed information
      # for the new reporting system to report
      class ApplicationInventory < Contrast::Agent::Reporting::ReportingEvent
        attr_accessor :routes, :agent_session_id_value

        class << self
          def convert app_update_dtm
            app_inventory = new
            app_inventory.attach_data app_update_dtm
            app_inventory
          end
        end

        def initialize
          @routes = []
          @event_type = :application_inventory
          @event_method = :POST
          @event_endpoint = Contrast::Agent::Reporting::Endpoints.application_inventory
          super
        end

        def to_controlled_hash
          {
              session_id: agent_session_id_value,
              routes: routes.map(&:to_controlled_hash)
          }
        end

        # @param inventory_dtm [Contrast::Api::Dtm::ApplicationUpdate]
        # @return [Contrast::Agent::Reporting::ApplicationInventory]
        def attach_data inventory_dtm
          inventory_dtm.routes.each do |route|
            @routes << Contrast::Agent::Reporting::DiscoveredRoute.convert(route)
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
contrast-agent-5.3.0 lib/contrast/agent/reporting/reporting_events/application_inventory.rb
contrast-agent-5.2.0 lib/contrast/agent/reporting/reporting_events/application_inventory.rb
contrast-agent-5.1.0 lib/contrast/agent/reporting/reporting_events/application_inventory.rb
contrast-agent-5.0.0 lib/contrast/agent/reporting/reporting_events/application_inventory.rb