Sha256: 1a8c706f33491461afbee2efd2309e83b4044ad469f6ffb647bdadd547fc0bc1

Contents?: true

Size: 1.06 KB

Versions: 15

Compression:

Stored size: 1.06 KB

Contents

require 'net/ssh'
require 'net/ssh/gateway'

class Aerosol::Connection
  include Dockly::Util::DSL
  include Dockly::Util::Logger::Mixin

  logger_prefix '[aerosol connection]'
  dsl_attribute :user, :host, :jump

  def with_connection(overridden_host=nil, &block)
    actual_host = overridden_host || host
    unless actual_host.is_a?(String)
      actual_host = actual_host.address
    end

    if jump
      info "connecting to gateway #{jump[:user] || user}@#{jump[:host]}"
      gateway = nil
      Timeout.timeout(20) do
        gateway = Net::SSH::Gateway.new(jump[:host], jump[:user] || user, :forward_agent => true)
      end

      begin
        info "connecting to #{user}@#{actual_host} through gateway"
        gateway.ssh(actual_host, user, &block)
      ensure
        info "shutting down gateway connection"
        gateway.shutdown!
      end
    else
      info "connecting to #{user}@#{actual_host}"
      Net::SSH.start(actual_host, user, &block)
    end
  rescue Timeout::Error => ex
    error "Timeout error #{ex.message}"
    error ex.backtrace.join("\n")
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
aerosol-1.10.0 lib/aerosol/connection.rb
aerosol-1.9.2 lib/aerosol/connection.rb
aerosol-1.9.1 lib/aerosol/connection.rb
aerosol-1.9.0 lib/aerosol/connection.rb
aerosol-1.8.0 lib/aerosol/connection.rb
aerosol-1.7.1 lib/aerosol/connection.rb
aerosol-1.7.0 lib/aerosol/connection.rb
aerosol-1.7.0.pre.1 lib/aerosol/connection.rb
aerosol-1.6.0 lib/aerosol/connection.rb
aerosol-1.5.1 lib/aerosol/connection.rb
aerosol-1.3.0 lib/aerosol/connection.rb
aerosol-1.2.0 lib/aerosol/connection.rb
aerosol-1.1.0 lib/aerosol/connection.rb
aerosol-1.0.2 lib/aerosol/connection.rb
aerosol-1.0.1 lib/aerosol/connection.rb