Sha256: c89d9df0742b8350b3ebf8c482e9f47512bddac642193487babae7150c929e6f

Contents?: true

Size: 1.71 KB

Versions: 11

Compression:

Stored size: 1.71 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/components/logger'
require 'contrast/agent/inventory/database_config'

module Contrast
  module Agent
    module Inventory
      module Policy
        # This Module is how we apply the Data Store detection required for the
        # FlowMap feature. It is called from our patches of the targeted methods
        # in which database operations occur. It is responsible for deciding if
        # the given invocation is worth reporting or not.
        module DataStores
          class << self
            extend Contrast::Components::Logger::InstanceMethods

            # The key used in policy.json to indicate the database type to
            # report.
            DATA_STORE_MARKER = 'data_store'

            def report_data_store _method, _exception, properties, object, _args
              return unless ::Contrast::INVENTORY.enabled?

              marker = properties[DATA_STORE_MARKER]
              return unless marker

              file_report(marker)
            rescue StandardError => e
              logger.error('Error reporting database call', e, object: object)
            end

            private

            def file_report data_store
              return unless data_store

              context = Contrast::Agent::REQUEST_TRACKER.current
              return unless context&.activity

              context.activity.query_count += 1
              return unless context.activity.query_count == 1

              Contrast::Agent::Inventory::DatabaseConfig.append_db_config(context.activity)
            end
          end
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
contrast-agent-6.4.0 lib/contrast/agent/inventory/policy/datastores.rb
contrast-agent-6.3.0 lib/contrast/agent/inventory/policy/datastores.rb
contrast-agent-6.2.0 lib/contrast/agent/inventory/policy/datastores.rb
contrast-agent-6.1.2 lib/contrast/agent/inventory/policy/datastores.rb
contrast-agent-6.1.1 lib/contrast/agent/inventory/policy/datastores.rb
contrast-agent-6.1.0 lib/contrast/agent/inventory/policy/datastores.rb
contrast-agent-6.0.0 lib/contrast/agent/inventory/policy/datastores.rb
contrast-agent-5.3.0 lib/contrast/agent/inventory/policy/datastores.rb
contrast-agent-5.2.0 lib/contrast/agent/inventory/policy/datastores.rb
contrast-agent-5.1.0 lib/contrast/agent/inventory/policy/datastores.rb
contrast-agent-5.0.0 lib/contrast/agent/inventory/policy/datastores.rb