# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details. # frozen_string_literal: true cs__scoped_require 'contrast/components/interface' cs__scoped_require 'contrast/utils/data_store_util' module Contrast module CoreExtensions module Inventory # 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 include Contrast::Components::Interface access_component :logging, :analysis # The key used in policy.json to indicate the database type to # report. DATA_STORE_MARKER = 'data_store' def cs__patched_report_data_store _method, _exception, properties, object, _args return unless INVENTORY.enabled? marker = properties[DATA_STORE_MARKER] return unless marker Contrast::Utils::DataStoreUtil.report_data_store(marker) rescue StandardError => e logger.error(e, "Error reporting database call in #{ object }") end end end end end end