Sha256: 7799ee3721ca0d366db3e6bdc0e745b9d08e3348450aa7f953081a29490b14bf

Contents?: true

Size: 970 Bytes

Versions: 28

Compression:

Stored size: 970 Bytes

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)
        @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])
      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

28 entries across 28 versions & 1 rubygems

Version Path
arql-0.3.6 lib/arql/ssh_proxy.rb
arql-0.3.5 lib/arql/ssh_proxy.rb
arql-0.3.3 lib/arql/ssh_proxy.rb
arql-0.3.2 lib/arql/ssh_proxy.rb
arql-0.3.1 lib/arql/ssh_proxy.rb
arql-0.3.0 lib/arql/ssh_proxy.rb
arql-0.2.14 lib/arql/ssh_proxy.rb
arql-0.2.13 lib/arql/ssh_proxy.rb
arql-0.2.12 lib/arql/ssh_proxy.rb
arql-0.2.11 lib/arql/ssh_proxy.rb
arql-0.2.10 lib/arql/ssh_proxy.rb
arql-0.2.9 lib/arql/ssh_proxy.rb
arql-0.2.8 lib/arql/ssh_proxy.rb
arql-0.2.7 lib/arql/ssh_proxy.rb
arql-0.2.6 lib/arql/ssh_proxy.rb
arql-0.2.5 lib/arql/ssh_proxy.rb
arql-0.2.4 lib/arql/ssh_proxy.rb
arql-0.2.3 lib/arql/ssh_proxy.rb
arql-0.2.2 lib/arql/ssh_proxy.rb
arql-0.2.1 lib/arql/ssh_proxy.rb