Sha256: 8bccfe33720410e92da324e901217970aaef7789409f1c616e5602311e0d1ae5

Contents?: true

Size: 1.18 KB

Versions: 10

Compression:

Stored size: 1.18 KB

Contents

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

module Arql
  class SSHProxy
    attr_accessor :config, :ssh_gateway, :local_ssh_proxy_port

    def initialize(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"
    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

    def database_host_port
      {
        host: '127.0.0.1',
        port: @local_ssh_proxy_port
      }
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
arql-0.4.12 lib/arql/ssh_proxy.rb
arql-0.4.11 lib/arql/ssh_proxy.rb
arql-0.4.10 lib/arql/ssh_proxy.rb
arql-0.4.8 lib/arql/ssh_proxy.rb
arql-0.4.7 lib/arql/ssh_proxy.rb
arql-0.4.6 lib/arql/ssh_proxy.rb
arql-0.4.3 lib/arql/ssh_proxy.rb
arql-0.4.2 lib/arql/ssh_proxy.rb
arql-0.4.1 lib/arql/ssh_proxy.rb
arql-0.4.0 lib/arql/ssh_proxy.rb