Module: ActiveRecordMysqlRepl::SSHTunnel

Defined in:
lib/active_record_mysql_repl/ssh_tunnel.rb

Constant Summary collapse

EPHEMERAL_PORT =
0

Class Method Summary collapse

Class Method Details

.tunnel(db_config) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/active_record_mysql_repl/ssh_tunnel.rb', line 10

def self.tunnel(db_config)
  unless db_config.bastion
    return yield(db_config.port) if block_given?
  end

  puts "Establishing ssh tunnel to #{db_config.remote_host}:#{db_config.port} via #{db_config.ssh_user}@#{db_config.bastion}".gray

  gateway = Net::SSH::Gateway.new(db_config.bastion, db_config.ssh_user)
  gateway.open(db_config.remote_host, db_config.port) do |port|
    yield(port) if block_given?
  end
end