Skip to content

Commit fa27def

Browse files
committed
Revert "Fix a crash when we can't connect to PG"
This reverts commit b6deb6a.
1 parent f0f5772 commit fa27def

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

lib/metasploit/framework/command/base.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ def self.require_environment!
6060
# the configuration from the parsed options.
6161
parsed_options.configure(Rails.application)
6262

63+
# support disabling the database
64+
unless parsed_options.options.database.disable
65+
Metasploit::Framework::Require.optionally_active_record_railtie
66+
end
67+
6368
Rails.application.require_environment!
6469

6570
parsed_options

lib/metasploit/framework/require.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,31 @@ def self.optionally(name, without_warning)
3434
end
3535
end
3636

37+
# Tries to `require 'active_record/railtie'` to define the activerecord Rails initializers and rake tasks.
38+
#
39+
# @example Optionally requiring 'active_record/railtie'
40+
# require 'metasploit/framework/require'
41+
#
42+
# class MyClass
43+
# def setup
44+
# if database_enabled
45+
# Metasploit::Framework::Require.optionally_active_record_railtie
46+
# end
47+
# end
48+
# end
49+
#
50+
# @return [void]
51+
def self.optionally_active_record_railtie
52+
if ::File.exist?(Rails.application.config.paths['config/database'].first)
53+
optionally(
54+
'active_record/railtie',
55+
'activerecord not in the bundle, so database support will be disabled.'
56+
)
57+
else
58+
warn 'Could not find database.yml, so database support will be disabled.'
59+
end
60+
end
61+
3762
# Tries to `require 'metasploit/credential/creation'` and include it in the `including_module`.
3863
#
3964
# @param including_module [Module] `Class` or `Module` that wants to `include Metasploit::Credential::Creation`.

0 commit comments

Comments
 (0)