Class: Heroku::Client::Rendezvous

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/heroku/client/rendezvous.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from Helpers

#action, #app_owner, #ask, #confirm, #confirm_command, #create_git_remote, #default_org_host, #deprecate, #display, #display_header, #display_object, #display_row, #display_table, #error, error_with_failure, error_with_failure=, extended, extended_into, #fail, #format_bytes, #format_date, #format_error, #format_with_bang, #get_terminal_environment, #git, #has_git?, #home_directory, #hprint, #hputs, included, included_into, #json_decode, #json_encode, #launchy, #line_formatter, #longest, #org?, #org_host, #output_with_bang, #quantify, #redisplay, #retry_on_exception, #run_command, #running_on_a_mac?, #running_on_windows?, #set_buffer, #shell, #spinner, #status, #string_distance, #styled_array, #styled_error, #styled_hash, #styled_header, #suggestion, #time_ago, #truncate, #with_tty

Constructor Details

- (Rendezvous) initialize(opts)

Returns a new instance of Rendezvous



14
15
16
17
18
19
20
# File 'lib/heroku/client/rendezvous.rb', line 14

def initialize(opts)
  @rendezvous_url = opts[:rendezvous_url]
  @connect_timeout = opts[:connect_timeout]
  @activity_timeout = opts[:activity_timeout]
  @input = opts[:input]
  @output = opts[:output]
end

Instance Attribute Details

- (Object) activity_timeout (readonly)

Returns the value of attribute activity_timeout



12
13
14
# File 'lib/heroku/client/rendezvous.rb', line 12

def activity_timeout
  @activity_timeout
end

- (Object) connect_timeout (readonly)

Returns the value of attribute connect_timeout



12
13
14
# File 'lib/heroku/client/rendezvous.rb', line 12

def connect_timeout
  @connect_timeout
end

- (Object) input (readonly)

Returns the value of attribute input



12
13
14
# File 'lib/heroku/client/rendezvous.rb', line 12

def input
  @input
end

- (Object) on_connect(&blk) (readonly)

Returns the value of attribute on_connect



12
13
14
# File 'lib/heroku/client/rendezvous.rb', line 12

def on_connect
  @on_connect
end

- (Object) output (readonly)

Returns the value of attribute output



12
13
14
# File 'lib/heroku/client/rendezvous.rb', line 12

def output
  @output
end

- (Object) rendezvous_url (readonly)

Returns the value of attribute rendezvous_url



12
13
14
# File 'lib/heroku/client/rendezvous.rb', line 12

def rendezvous_url
  @rendezvous_url
end

Instance Method Details

- (Object) start



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/heroku/client/rendezvous.rb', line 27

def start
  uri = URI.parse(rendezvous_url)
  host, port, secret = uri.host, uri.port, uri.path[1..-1]

  ssl_socket = Timeout.timeout(connect_timeout) do
    ssl_context = OpenSSL::SSL::SSLContext.new
    ssl_context.ssl_version = :TLSv1
    
    if Heroku::Auth.verify_host?(host)
      ssl_context.ca_file     = File.expand_path("../../../../data/cacert.pem", __FILE__)
      ssl_context.verify_mode = OpenSSL::SSL::VERIFY_PEER
    end

    tcp_socket = TCPSocket.open(host, port)
    ssl_socket = OpenSSL::SSL::SSLSocket.new(tcp_socket, ssl_context)
    ssl_socket.connect
    ssl_socket.puts(secret)
    ssl_socket.readline
    ssl_socket
  end

  on_connect.call if on_connect

  readables = [input, ssl_socket].compact

  begin
    loop do
      if o = IO.select(readables, nil, nil, activity_timeout)
        if (input && (o.first.first == input))
          begin
            data = input.readpartial(10000)
          rescue EOFError
            ssl_socket.write(4.chr)
            ssl_socket.flush
            readables.delete(input)
            next
          end
          if running_on_windows?
            data.gsub!("\r\n", "\n") # prevent double CRs
          end
          ssl_socket.write(data)
          ssl_socket.flush
        elsif (o.first.first == ssl_socket)
          begin
            data = ssl_socket.readpartial(10000)
          rescue EOFError
            break
          end
          output.write(fixup(data))
        end
      else
        raise(Timeout::Error.new)
      end
    end
  rescue Interrupt
    ssl_socket.write(3.chr)
    ssl_socket.flush
    retry
  rescue SignalException => e
    if Signal.list["QUIT"] == e.signo
      ssl_socket.write(28.chr)
      ssl_socket.flush
      retry
    end
    raise
  rescue Errno::EIO
  end
end