Sha256: 08d6be1e4d98b19ee2716188ad8f4465e8af86d5ea32448a2d745f83a679fa80

Contents?: true

Size: 1.33 KB

Versions: 4

Compression:

Stored size: 1.33 KB

Contents

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

require 'contrast/agent/inventory/dependencies'
require 'contrast/components/interface'
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
        include Contrast::Components::Interface

        access_component :analysis

        # Report the dependencies of this application
        #
        # @return [Array<Contrast::Api::Dtm::Library>] protobuf form of the
        #   Gem::Specification that have been loaded for this application.
        def library_pb_list
          return Contrast::Utils::ObjectShare::EMPTY_ARRAY unless INVENTORY.enabled?
          return Contrast::Utils::ObjectShare::EMPTY_ARRAY unless 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::Api::Dtm::Library.build(digest, spec)
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
contrast-agent-4.8.0 lib/contrast/agent/inventory/dependency_analysis.rb
contrast-agent-4.7.0 lib/contrast/agent/inventory/dependency_analysis.rb
contrast-agent-4.6.0 lib/contrast/agent/inventory/dependency_analysis.rb
contrast-agent-4.5.0 lib/contrast/agent/inventory/dependency_analysis.rb