Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/msfdb_helpers/db_interface.rb
Views: 11766
module MsfdbHelpers1class DbInterface23def initialize(options)4@options = options5end67def init8raise NotImplementedError9end1011def delete12raise NotImplementedError13end1415def start16raise NotImplementedError17end1819def stop20raise NotImplementedError21end2223def restart24raise NotImplementedError25end2627def status28raise NotImplementedError29end3031def write_db_client_auth_config(client_auth_config)32puts "Writing client authentication configuration file #{client_auth_config}"33File.open(client_auth_config, 'w') do |f|34f.puts "host \"#{@options[:msf_db_name]}\" \"#{@options[:msf_db_user]}\" 127.0.0.1/32 md5"35f.puts "host \"#{@options[:msftest_db_name]}\" \"#{@options[:msftest_db_user]}\" 127.0.0.1/32 md5"36f.puts "host \"postgres\" \"#{@options[:msftest_db_user]}\" 127.0.0.1/32 md5"37f.puts 'host "template1" all 127.0.0.1/32 trust'38if Gem.win_platform?39f.puts 'host all all 127.0.0.1/32 trust'40f.puts 'host all all ::1/128 trust'41else42f.puts 'local all all trust'43end44end45end4647def self.requirements48[]49end5051def run_cmd(cmd, input: nil, env: {})52puts "run_cmd: cmd=#{cmd}, input=#{input}, env=#{env}" if @options[:debug]5354output, status = Open3.capture2e(env, cmd)55if @options[:debug]56puts "'#{cmd}' returned #{status.exitstatus}"57puts output58end59status.exitstatus60end6162def run_psql(cmd, socket_directory= "#{Dir.tmpdir}", db_name: 'postgres')63if @options[:debug]64puts "psql -h #{socket_directory} -p #{@options[:db_port]} -c \"#{cmd};\" #{db_name}"65end6667run_cmd("psql -h #{socket_directory} -p #{@options[:db_port]} -c \"#{cmd};\" #{db_name}")68end6970end71end727374