Sha256: 00d54363b8e36e1771bdf52ae87d00af929ab4ad52133935aa323255b117a96e

Contents?: true

Size: 878 Bytes

Versions: 1

Compression:

Stored size: 878 Bytes

Contents

require 'net/ssh/gateway'

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

1 entries across 1 versions & 1 rubygems

Version Path
arql-0.1.23 lib/arql/ssh_proxy.rb