Sha256: eba38a7998bb9d178ebaa2cf80d462ce710fc67c2a7d4e3a8e937f8907f0e878

Contents?: true

Size: 1.34 KB

Versions: 2

Compression:

Stored size: 1.34 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/agent/reporting/reporting_events/library_discovery'
require 'contrast/agent/inventory/dependencies'
require 'contrast/utils/object_share'

module Contrast
  module Agent
    module Inventory
      # Used to collect dependencies of the application for reporting
      class DependencyAnalysis
        include Singleton
        include Contrast::Agent::Inventory::Dependencies

        # Report the dependencies of this application
        #
        # @return [Array<Contrast::Agent::Reporting::LibraryDiscovery>] direct report form of
        #   Gem::Specification that have been loaded for this application.
        def library_pb_list
          return Contrast::Utils::ObjectShare::EMPTY_ARRAY unless ::Contrast::INVENTORY.enabled?
          return Contrast::Utils::ObjectShare::EMPTY_ARRAY unless ::Contrast::INVENTORY.analyze_libraries?

          loaded_specs.each_with_object([]) do |(_name, spec), reported_lib_list|
            next unless spec
            next unless (digest = Contrast::Utils::Sha256Builder.instance.build_from_spec(spec))

            reported_lib_list << Contrast::Agent::Reporting::LibraryDiscovery.new(digest, spec)
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
contrast-agent-6.4.0 lib/contrast/agent/inventory/dependency_analysis.rb
contrast-agent-6.3.0 lib/contrast/agent/inventory/dependency_analysis.rb