Sha256: ddb8763bfbcad773a7175437c06d6c4eefab6b17b0c27947455f299ddde052ea

Contents?: true

Size: 1.42 KB

Versions: 15

Compression:

Stored size: 1.42 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/application_reporting_event'
require 'contrast/agent/reporting/reporting_events/library_usage_observation'
require 'contrast/components/logger'

module Contrast
  module Agent
    module Reporting
      # List of libraries that have been observed to have something loaded or executed.
      class ObservedLibraryUsage < Contrast::Agent::Reporting::ApplicationReportingEvent
        include Contrast::Components::Logger::InstanceMethods

        # @return Array[Contrast::Agent::Reporting::LibraryUsageObservation]
        attr_reader :observations

        def initialize
          @event_endpoint = Contrast::Agent::Reporting::Endpoints.library_usage
          @observations = []
          super
        end

        def file_name
          'library-observation'
        end

        def to_controlled_hash
          begin
            validate
          rescue ArgumentError => e
            logger.error('ObservedLibraryUsage validation failed with: ', e)
            return
          end

          { observations: @observations.map(&:to_controlled_hash) }
        end

        def validate
          raise(ArgumentError, "#{ self } did not have observations. Unable to continue.") if observations.empty?
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
contrast-agent-6.11.0 lib/contrast/agent/reporting/reporting_events/observed_library_usage.rb
contrast-agent-6.10.0 lib/contrast/agent/reporting/reporting_events/observed_library_usage.rb
contrast-agent-6.9.0 lib/contrast/agent/reporting/reporting_events/observed_library_usage.rb
contrast-agent-6.8.0 lib/contrast/agent/reporting/reporting_events/observed_library_usage.rb
contrast-agent-6.7.0 lib/contrast/agent/reporting/reporting_events/observed_library_usage.rb
contrast-agent-6.6.5 lib/contrast/agent/reporting/reporting_events/observed_library_usage.rb
contrast-agent-6.6.4 lib/contrast/agent/reporting/reporting_events/observed_library_usage.rb
contrast-agent-6.6.3 lib/contrast/agent/reporting/reporting_events/observed_library_usage.rb
contrast-agent-6.6.2 lib/contrast/agent/reporting/reporting_events/observed_library_usage.rb
contrast-agent-6.6.1 lib/contrast/agent/reporting/reporting_events/observed_library_usage.rb
contrast-agent-6.6.0 lib/contrast/agent/reporting/reporting_events/observed_library_usage.rb
contrast-agent-6.5.1 lib/contrast/agent/reporting/reporting_events/observed_library_usage.rb
contrast-agent-6.5.0 lib/contrast/agent/reporting/reporting_events/observed_library_usage.rb
contrast-agent-6.4.0 lib/contrast/agent/reporting/reporting_events/observed_library_usage.rb
contrast-agent-6.3.0 lib/contrast/agent/reporting/reporting_events/observed_library_usage.rb