Use connection string for standalone setups

This commit is contained in:
dwelch-r7
2021-04-29 12:20:29 +01:00
parent 5154000f6e
commit 9c19f1ad2c
4 changed files with 13 additions and 11 deletions
+1 -1
View File
@@ -117,7 +117,7 @@ class PgCtl < DbInterface
run_psql("alter role #{@options[:msf_db_user]} with password '#{msf_pass}'")
run_psql("alter role #{@options[:msftest_db_user]} with password '#{msftest_pass}'")
conn = PG.connect(host: '127.0.0.1', dbname: 'postgres', port: @options[:db_port], user: @options[:msf_db_user], password: msf_pass)
conn = PG.connect(host: @options[:db_host], dbname: 'postgres', port: @options[:db_port], user: @options[:msf_db_user], password: msf_pass)
conn.exec("CREATE DATABASE #{@options[:msf_db_name]}")
conn.exec("CREATE DATABASE #{@options[:msftest_db_name]}")
conn.finish
+1 -1
View File
@@ -131,7 +131,7 @@ class PgCtlcluster < DbInterface
run_psql("alter role #{@options[:msf_db_user]} with password '#{msf_pass}'")
run_psql("alter role #{@options[:msftest_db_user]} with password '#{msftest_pass}'")
conn = PG.connect(host: '127.0.0.1', dbname: 'postgres', port: @options[:db_port], user: @options[:msf_db_user], password: msf_pass)
conn = PG.connect(host: @options[:db_host], dbname: 'postgres', port: @options[:db_port], user: @options[:msf_db_user], password: msf_pass)
conn.exec("CREATE DATABASE #{@options[:msf_db_name]}")
conn.exec("CREATE DATABASE #{@options[:msftest_db_name]}")
conn.finish
+5 -4
View File
@@ -2,12 +2,13 @@ require 'msfdb_helpers/db_interface'
class Standalone < DbInterface
def initialize(options:, msf_pass:, msftest_pass:, db_conf:)
def initialize(options:, db_conf:, connection_string:)
@options = options
@msf_pass = msf_pass
@msftest_pass = msftest_pass
@db_conf = db_conf
@conn = PG.connect(host: '127.0.0.1', dbname: 'postgres', port: @options[:db_port], user: @options[:msf_db_admin_username], password: @options[:msf_db_admin_pass])
@conn = PG.connect(connection_string)
conninfo = @conn.conninfo_hash
@options[:db_port] = conninfo[:port]
@options[:db_host] = conninfo[:host]
super(options)
end
+6 -5
View File
@@ -64,6 +64,7 @@ require 'msfenv'
msf_db_user: 'msf',
msftest_db_name: 'msftest',
msftest_db_user: 'msftest',
db_host: '127.0.0.1',
db_port: 5433,
db_pool: 200,
address: 'localhost',
@@ -223,7 +224,7 @@ def write_db_config
database: #{@options[:msf_db_name]}
username: #{@options[:msf_db_user]}
password: #{@msf_pass}
host: 127.0.0.1
host: #{@options[:db_host]}
port: #{@options[:db_port]}
pool: #{@options[:db_pool]}
@@ -807,8 +808,8 @@ def parse_args(args)
@options[:msf_db_admin_username] = p
}
opts.on('--standalone', 'Use a pre-existing database cluster for initialization') {
@standalone = true
opts.on('--connection-string URI', 'Use a pre-existing database cluster for initialization') { |c|
@connection_string = c
}
opts.separator('')
@@ -989,8 +990,8 @@ if $PROGRAM_NAME == __FILE__
update_db_port
if @standalone
@db_driver = Standalone.new(options: @options, msf_pass: @msf_pass, msftest_pass: @msftest_pass, db_conf: @db_conf)
if @connection_string
@db_driver = Standalone.new(options: @options, db_conf: @db_conf, connection_string: @connection_string)
elsif installed?("pg_ctl") && has_requirements(PgCtl.requirements)
@db_driver = PgCtl.new(db_path: @db, options: @options, localconf: @localconf, db_conf: @db_conf)
elsif installed?("pg_ctlcluster") && has_requirements(PgCtlcluster.requirements)