Sha256: 18c9a964848ea8ef075103ae8e31ed975d72a6bbd0e50debb3a185650d25a606

Contents?: true

Size: 1.46 KB

Versions: 4

Compression:

Stored size: 1.46 KB

Contents

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

module Contrast
  module Agent
    module Reporting
      #
      # @attr_accessor id - [String]  - Hash of library as identified by the agent
      # @attr_accessor names Array[String] - List of file paths that have been loaded out of or executed by the library
      #
      class LibraryUsageObservation
        attr_accessor :id, :names

        class << self
          # Convert a DTM for SpeedRacer to an Event for TeamServer.
          #
          # @param usage_dtm [Contrast::Api::Dtm::LibraryUsageUpdate]
          # @return [Contrast::Agent::Reporting::LibraryUsageObservation]
          def convert usage_dtm
            observation = new
            observation.attach_data(usage_dtm)
            observation
          end
        end

        def initialize
          @names = []
        end

        def attach_data usage_dtm
          @id = usage_dtm.hash_code
          @names = usage_dtm.class_names.keys
        end

        def to_controlled_hash
          validate
          {
              id: @id,
              names: @names
          }
        end

        def validate
          raise(ArgumentError, "#{ self } did not have a proper id. Unable to continue.") unless id
          raise(ArgumentError, "#{ self } did not have a proper names. Unable to continue.") if names.empty?
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
contrast-agent-5.3.0 lib/contrast/agent/reporting/reporting_events/library_usage_observation.rb
contrast-agent-5.2.0 lib/contrast/agent/reporting/reporting_events/library_usage_observation.rb
contrast-agent-5.1.0 lib/contrast/agent/reporting/reporting_events/library_usage_observation.rb
contrast-agent-5.0.0 lib/contrast/agent/reporting/reporting_events/library_usage_observation.rb