Sha256: ed4b285affe9ed2a5a4620ac992127bbd82775ad81b13a81a0f6778281a8927b

Contents?: true

Size: 1.78 KB

Versions: 2

Compression:

Stored size: 1.78 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. Reporting those components or details discovered at
      # startup, or as soon as possible, but not necessarily seen used by the application. Each of
      # these messages should only be sent once per application.
      class ApplicationInventory < Contrast::Agent::Reporting::ApplicationReportingEvent
        # @param [Array<Contrast::Agent::Reporting::DiscoveredRoute>] the routes registered to this application, as
        #   discovered during first request processing.
        attr_reader :routes

        def initialize
          @event_type = :application_inventory
          @event_method = :POST
          @event_endpoint = Contrast::Agent::Reporting::Endpoints.application_inventory
          # The API spec limits us to 500 routes, so we'll enforce that here to not hold on to superfulous data.
          @routes = Contrast::Agent.framework_manager.find_route_discovery_data&.take(500)
          super
        end

        def file_name
          'applications-inventory'
        end

        def to_controlled_hash
          {
              session_id: ::Contrast::ASSESS.session_id,
              # documentation lists routes as deprecated from the agent_ng_endpoints.yml
              routes: routes.map(&:to_controlled_hash)
          }
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
contrast-agent-6.11.0 lib/contrast/agent/reporting/reporting_events/application_inventory.rb
contrast-agent-6.10.0 lib/contrast/agent/reporting/reporting_events/application_inventory.rb