Class: Capistrano::Configuration::Connections::GatewayConnectionFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/capistrano/configuration/connections.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(gateway, options) ⇒ GatewayConnectionFactory

Returns a new instance of GatewayConnectionFactory.


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/capistrano/configuration/connections.rb', line 25

def initialize(gateway, options)
  @options = options
  @options[:logger].debug "Creating gateway using #{[*gateway].join(', ')}" if @options[:logger]
  Thread.abort_on_exception = true
  @gateways = [*gateway].collect { |g| ServerDefinition.new(g) }
  tunnel = SSH.connection_strategy(@gateways[0], @options) do |host, user, connect_options|
    Net::SSH::Gateway.new(host, user, connect_options)
  end
  @gateway = (@gateways[1..-1]).inject(tunnel) do |tunnel, destination|
    @options[:logger].debug "Creating tunnel to #{destination}" if @options[:logger]
    local_host = ServerDefinition.new("127.0.0.1", :user => destination.user, :port => tunnel.open(destination.host, (destination.port || 22)))
    SSH.connection_strategy(local_host, @options) do |host, user, connect_options|
      Net::SSH::Gateway.new(host, user, connect_options)
    end
  end
end

Instance Method Details

#connect_to(server) ⇒ Object


42
43
44
45
46
47
48
# File 'lib/capistrano/configuration/connections.rb', line 42

def connect_to(server)
  @options[:logger].debug "establishing connection to `#{server}' via gateway" if @options[:logger]
  local_host = ServerDefinition.new("127.0.0.1", :user => server.user, :port => @gateway.open(server.host, server.port || 22))
  session = SSH.connect(local_host, @options)
  session.xserver = server
  session
end