Class: Net::SSH::Proxy::Gateway
- Inherits:
-
Object
- Object
- Net::SSH::Proxy::Gateway
- Defined in:
- lib/net/ssh/proxy/gateway.rb,
lib/net/ssh/proxy/gateway/version.rb
Overview
Net::SSH::Proxy::Gateway is like any Net::SSH::Proxy (Command, Jump, SOCKS, ..) and can be passed to Net::SSH.start through the proxy: keyword.
Internally it uses Net::SSH::Gateway from the net-ssh-gateway gem.
Constant Summary collapse
- VERSION =
'0.2.0'.freeze
Instance Method Summary collapse
- #gateway ⇒ Object
-
#initialize(host, user, gateway = nil, **options) ⇒ Gateway
constructor
A new instance of Gateway.
- #open(host, port, connection_options = nil) ⇒ Socket
-
#shutdown! ⇒ Object
Shuts down the Net::SSH::Gateway instance.
Constructor Details
#initialize(host, user, gateway = nil, **options) ⇒ Gateway
Returns a new instance of Gateway.
16 17 18 19 20 21 22 |
# File 'lib/net/ssh/proxy/gateway.rb', line 16 def initialize(host, user, gateway = nil, **) if gateway @gateway = gateway else @gateway_options = [host, user, ] end end |
Instance Method Details
#gateway ⇒ Object
24 25 26 |
# File 'lib/net/ssh/proxy/gateway.rb', line 24 def gateway @gateway ||= Net::SSH::Gateway.new(*@gateway_options) end |
#open(host, port, connection_options = nil) ⇒ Socket
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/net/ssh/proxy/gateway.rb', line 32 def open(host, port, = nil) ensure_connected! local_port = gateway.open(host, &.dig(:port) || 22) io = Socket.tcp('localhost'.freeze, local_port, nil, nil, connect_timeout: &.dig(:timeout)) Thread.new(io, local_port, self) do |io, local_port, gateway| Thread.current.report_on_exception = false Thread.pass until io.closed? gateway.close(local_port) end io rescue StandardError => ex io&.close unless io&.closed? @gateway&.close(local_port) if local_port raise end |
#shutdown! ⇒ Object
Shuts down the Net::SSH::Gateway instance
52 53 54 55 56 |
# File 'lib/net/ssh/proxy/gateway.rb', line 52 def shutdown! @gateway&.shutdown! sleep 0.5 until !@gateway&.active? @gateway = nil end |