84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/rake/pro/ssh_tunnel.rb', line 84
def tunnel
host = gateway = port = jump = nil
cfg = Rake.application.cfg.values
if cfg.has_key?(:jumpbox)
jump = cfg[:jumpbox]
gateway = Net::SSH::Gateway.new(
jump[:host], jump[:user],
:keys => [jump[:keyfile]] )
host = "127.0.0.1"
port = gateway.open(cfg[:host], cfg[:port], jump[:port])
else
host = cfg[:host]
port = cfg[:port]
end
local = Rake::Local.new
yield(local, host, port) if block_given?
rescue Net::SSH::AuthenticationFailed => ex
puts "\nError: SSH Failed to Authenticate. You may need to run\n $ ssh-add ~/.ssh/#{jump[:keyfile]} # key file\n ** or add this line to your .bashrc.\n\n"
ensure
gateway.close(port) unless gateway.nil?
end
|