Sha256: 19bc2d1e5cdbb325780ab5724f4f08282379ca184223f4f6151d6a0c68a9a6b7

Contents?: true

Size: 1.59 KB

Versions: 18

Compression:

Stored size: 1.59 KB

Contents

# 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/reportable_hash'
require 'contrast/utils/duck_utils'

module Contrast
  module Agent
    module Reporting
      # The usage, meaning loaded files, of a library seen during this request
      class LibraryUsageObservation < Contrast::Agent::Reporting::ReportableHash
        # @param [String] Sha256Sum of library as identified by the agent
        attr_reader :id
        # @param [Array<String>] List of file paths that have been loaded out of or executed by the library
        attr_reader :names

        # @param id [String] Sha256Sum of library as identified by the agent
        # @param class_names [Array<String>] List of file paths that have been loaded out of or executed by the library
        def initialize id, class_names
          @id = id
          @names = class_names
          super()
        end

        # @raise [ArgumentError]
        def to_controlled_hash
          validate
          {
              id: @id,
              names: @names
          }
        end

        # @raise [ArgumentError]
        def validate
          if Contrast::Utils::DuckUtils.empty_duck?(id)
            raise(ArgumentError, "#{ self } did not have a proper id. Unable to continue.")
          end
          if Contrast::Utils::DuckUtils.empty_duck?(names)
            raise(ArgumentError, "#{ self } did not have a proper names. Unable to continue.")
          end

          nil
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
contrast-agent-7.6.1 lib/contrast/agent/reporting/reporting_events/library_usage_observation.rb
contrast-agent-7.6.0 lib/contrast/agent/reporting/reporting_events/library_usage_observation.rb
contrast-agent-7.5.0 lib/contrast/agent/reporting/reporting_events/library_usage_observation.rb
contrast-agent-7.4.1 lib/contrast/agent/reporting/reporting_events/library_usage_observation.rb
contrast-agent-7.4.0 lib/contrast/agent/reporting/reporting_events/library_usage_observation.rb
contrast-agent-7.3.2 lib/contrast/agent/reporting/reporting_events/library_usage_observation.rb
contrast-agent-7.3.1 lib/contrast/agent/reporting/reporting_events/library_usage_observation.rb
contrast-agent-7.3.0 lib/contrast/agent/reporting/reporting_events/library_usage_observation.rb
contrast-agent-7.2.0 lib/contrast/agent/reporting/reporting_events/library_usage_observation.rb
contrast-agent-7.1.0 lib/contrast/agent/reporting/reporting_events/library_usage_observation.rb
contrast-agent-7.0.0 lib/contrast/agent/reporting/reporting_events/library_usage_observation.rb
contrast-agent-6.15.3 lib/contrast/agent/reporting/reporting_events/library_usage_observation.rb
contrast-agent-6.15.2 lib/contrast/agent/reporting/reporting_events/library_usage_observation.rb
contrast-agent-6.15.1 lib/contrast/agent/reporting/reporting_events/library_usage_observation.rb
contrast-agent-6.15.0 lib/contrast/agent/reporting/reporting_events/library_usage_observation.rb
contrast-agent-6.14.0 lib/contrast/agent/reporting/reporting_events/library_usage_observation.rb
contrast-agent-6.13.0 lib/contrast/agent/reporting/reporting_events/library_usage_observation.rb
contrast-agent-6.12.0 lib/contrast/agent/reporting/reporting_events/library_usage_observation.rb