Sha256: ca59a58d86a927b17140250ccb801a26aa3c74564737aa62cef42b07014ab664

Contents?: true

Size: 1.16 KB

Versions: 25

Compression:

Stored size: 1.16 KB

Contents

require 'net/ssh/gateway'
require 'arql/ssh_proxy_patch'

module Arql
  class SSHProxy
    class << self

      attr_accessor :config, :ssh_gateway, :local_ssh_proxy_port

      def connect(config)
        print "Establishing SSH connection to #{config[:host]}:#{config[:port]}"
        @config = config
        @ssh_gateway = Net::SSH::Gateway.new(config[:host], config[:user], config.slice(:port, :password).symbolize_keys.merge(keepalive: true, keepalive_interval: 30, loop_wait: 1))
        @local_ssh_proxy_port = @ssh_gateway.open(config[:forward_host], config[:forward_port], config[:local_port])
        print "\u001b[2K"
        puts "\rSSH connection to #{config[:host]}:#{config[:port]} established"
        @local_ssh_proxy_port
      end

      def reconnect
        reconnect! unless @ssh_gateway.active?
      end

      def reconnect!
        @ssh_gateway.shutdown!
        @ssh_gateway = Net::SSH::Gateway.new(@config[:host], @config[:user], @config.slice(:port, :password).symbolize_keys)
        @ssh_gateway.open(config[:forward_host], config[:forward_port], @local_ssh_proxy_port)
      end

      def active?
        @ssh_gateway.active?
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
arql-0.3.31 lib/arql/ssh_proxy.rb
arql-0.3.30 lib/arql/ssh_proxy.rb
arql-0.3.29 lib/arql/ssh_proxy.rb
arql-0.3.28 lib/arql/ssh_proxy.rb
arql-0.3.27 lib/arql/ssh_proxy.rb
arql-0.3.26 lib/arql/ssh_proxy.rb
arql-0.3.25 lib/arql/ssh_proxy.rb
arql-0.3.24 lib/arql/ssh_proxy.rb
arql-0.3.23 lib/arql/ssh_proxy.rb
arql-0.3.22 lib/arql/ssh_proxy.rb
arql-0.3.21 lib/arql/ssh_proxy.rb
arql-0.3.20 lib/arql/ssh_proxy.rb
arql-0.3.19 lib/arql/ssh_proxy.rb
arql-0.3.18 lib/arql/ssh_proxy.rb
arql-0.3.17 lib/arql/ssh_proxy.rb
arql-0.3.16 lib/arql/ssh_proxy.rb
arql-0.3.15 lib/arql/ssh_proxy.rb
arql-0.3.14 lib/arql/ssh_proxy.rb
arql-0.3.13 lib/arql/ssh_proxy.rb
arql-0.3.12 lib/arql/ssh_proxy.rb