class SshTunnels::Tunnel
SSH Tunnel
Attributes
error[R]
name[R]
Public Class Methods
new(name, user, config, gateway, passphrase)
click to toggle source
# File lib/ssh_tunnels/tunnel.rb, line 8 def initialize(name, user, config, gateway, passphrase) @name = name @user = user @config = config @passphrase = passphrase @config = config @gateway = gateway @connection = nil end
Public Instance Methods
active?()
click to toggle source
# File lib/ssh_tunnels/tunnel.rb, line 37 def active? return false if @connection.nil? @connection.active? end
open()
click to toggle source
# File lib/ssh_tunnels/tunnel.rb, line 29 def open @connection = Net::SSH::Gateway.new(@gateway.fetch('host'), @user, options) @connection.open(remote_host, remote_port, local_port) rescue Errno::EADDRINUSE => e @error = e.to_s shutdown end
shutdown()
click to toggle source
# File lib/ssh_tunnels/tunnel.rb, line 43 def shutdown @connection.shutdown! end
to_s()
click to toggle source
# File lib/ssh_tunnels/tunnel.rb, line 18 def to_s base = "#{local_port}:#{remote_host}:#{remote_port}" return base unless @error "#{base} (#{@error})" end
toggle()
click to toggle source
# File lib/ssh_tunnels/tunnel.rb, line 25 def toggle active? ? shutdown : open end
Private Instance Methods
local_port()
click to toggle source
# File lib/ssh_tunnels/tunnel.rb, line 57 def local_port @config.fetch('local_port') end
options()
click to toggle source
# File lib/ssh_tunnels/tunnel.rb, line 61 def options { keepalive: true, keepalive_interval: 5, port: @gateway.fetch('port'), passphrase: @passphrase } end
remote_host()
click to toggle source
# File lib/ssh_tunnels/tunnel.rb, line 49 def remote_host @config.fetch('host') end
remote_port()
click to toggle source
# File lib/ssh_tunnels/tunnel.rb, line 53 def remote_port @config.fetch('remote_port') end