Module: Msf::DBManager::Adapter

Included in:
Msf::DBManager
Defined in:
lib/msf/core/db_manager/adapter.rb

Constant Summary collapse

ADAPTER =

The adapter to use to establish database connection.

'postgresql'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#driverObject

Returns the active driver



20
21
22
# File 'lib/msf/core/db_manager/adapter.rb', line 20

def driver
  @driver
end

#driversObject

Returns the list of usable database drivers



14
15
16
# File 'lib/msf/core/db_manager/adapter.rb', line 14

def drivers
  @drivers ||= []
end

Instance Method Details

#initialize_adapterObject

Scan through available drivers



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/msf/core/db_manager/adapter.rb', line 29

def initialize_adapter
  ActiveRecord.default_timezone = :utc

  if connection_established? && ApplicationRecord.connection_db_config.configuration_hash[:adapter] == ADAPTER
    dlog("Already established connection to #{ADAPTER}, so reusing active connection.")
    self.drivers << ADAPTER
    self.driver = ADAPTER
  else
    begin
      ApplicationRecord.establish_connection(adapter: ADAPTER)
      ApplicationRecord.remove_connection
    rescue Exception => error
      @adapter_error = error
    else
      self.drivers << ADAPTER
      self.driver = ADAPTER
    end
  end
end