Sha256: 374b6b71880e1cd7e5528dd1d2ac7deb4829816548cd46d79e3906a8cd9833cf

Contents?: true

Size: 1.65 KB

Versions: 1

Compression:

Stored size: 1.65 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/components/logger'

module Contrast
  module Agent
    module Reporting
      # This module will be used to store everything that would be sent
      # and depends on the response we receive
      module ReportingStorage
        class << self
          include Contrast::Components::Logger::InstanceMethods

          # So the collection will be used to store those events
          def collection
            @_collection ||= {}
          end

          # @param key[String] the key for the pair
          # @param value[Object] the value we need to store
          # @return [Object] the value we saved
          def []= key, value
            return unless key
            return unless value

            logger.debug('Saving new value', key: key)

            key = key.to_s.downcase.strip
            collection[key] = value

            value # rubocop:disable Lint/Void
          end

          # @param key[String] the key for the pair
          def [] key
            return unless key

            collection[key]
          end
          alias_method :get, :[]
          alias_method :set, :[]=

          def delete key
            return unless key

            collection.delete(key)
          end

          # @param rule_id [String] the rule_id
          # @return [Array, nil] return array with key and value of the pair
          def find_by_rule_id rule_id
            return unless rule_id

            collection.find { |_, v| v.rule_id == rule_id }
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
contrast-agent-7.6.1 lib/contrast/agent/reporting/reporting_utilities/reporting_storage.rb