Class: Net::SSH::Proxy::Jump
- Defined in:
- lib/net/ssh/proxy/jump.rb
Overview
An implementation of a jump proxy. To use it, instantiate it, then pass the instantiated object via the :proxy key to Net::SSH.start:
require 'net/ssh/proxy/jump'
proxy = Net::SSH::Proxy::Jump.new('user@proxy')
Net::SSH.start('host', 'user', :proxy => proxy) do |ssh|
...
end
Instance Attribute Summary collapse
-
#jump_proxies ⇒ Object
readonly
The jump proxies.
Attributes inherited from Command
#command_line, #command_line_template, #timeout
Instance Method Summary collapse
-
#build_proxy_command_equivalent(connection_options = nil) ⇒ Object
We cannot build the ProxyCommand template until we know if the :config option was specified during
Net::SSH.start. -
#initialize(jump_proxies) ⇒ Jump
constructor
Create a new socket factory that tunnels via multiple jump proxes as [user@]host.
-
#open(host, port, connection_options = nil) ⇒ Object
Return a new socket connected to the given host and port via the jump proxy that was requested when the socket factory was instantiated.
Methods inherited from Command
Constructor Details
Instance Attribute Details
#jump_proxies ⇒ Object (readonly)
The jump proxies
20 21 22 |
# File 'lib/net/ssh/proxy/jump.rb', line 20 def jump_proxies @jump_proxies end |
Instance Method Details
#build_proxy_command_equivalent(connection_options = nil) ⇒ Object
We cannot build the ProxyCommand template until we know if the :config option was specified during Net::SSH.start.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/net/ssh/proxy/jump.rb', line 37 def build_proxy_command_equivalent( = nil) first_jump, extra_jumps = jump_proxies.split(",", 2) config = && [:config] uri = URI.parse("ssh://#{first_jump}") template = "ssh" template << " -l #{uri.user}" if uri.user template << " -p #{uri.port}" if uri.port template << " -J #{extra_jumps}" if extra_jumps template << " -F #{config}" if config != true && config template << " -W %h:%p " template << uri.host @command_line_template = template end |
#open(host, port, connection_options = nil) ⇒ Object
Return a new socket connected to the given host and port via the jump proxy that was requested when the socket factory was instantiated.
30 31 32 33 |
# File 'lib/net/ssh/proxy/jump.rb', line 30 def open(host, port, = nil) build_proxy_command_equivalent() super end |