lib/cli/tunnel_helper.rb in vmc-0.3.16.beta.2 vs lib/cli/tunnel_helper.rb in vmc-0.3.16.beta.3

- old
+ new

@@ -37,11 +37,10 @@ def tunnel_auth tunnel_app_info[:env].each do |e| name, val = e.split("=", 2) return val if name == "CALDECOTT_AUTH" end - nil end def tunnel_url return @tunnel_url if @tunnel_url @@ -182,13 +181,11 @@ display "#{info[k]}".yellow end display '' end - def start_tunnel(service, local_port, conn_info, auth) - display "Starting tunnel to #{service.bold} on port #{local_port.to_s.bold}." - + def start_tunnel(local_port, conn_info, auth) @local_tunnel_thread = Thread.new do Caldecott::Client.start({ :local_port => local_port, :tun_url => tunnel_url, :dst_host => conn_info['hostname'], @@ -201,10 +198,12 @@ end at_exit { @local_tunnel_thread.kill } end + + def pick_tunnel_port(port) original = port PORT_RANGE.times do |n| begin @@ -228,12 +227,13 @@ end def wait_for_tunnel_start(port) 10.times do |n| begin - TCPSocket.open('localhost', port) + client = TCPSocket.open('localhost', port) display '' if n > 0 + client.close return true rescue => e display "Waiting for local tunnel to become available", false if n == 0 display '.', false sleep 1 @@ -295,30 +295,38 @@ def push_caldecott(token) client.create_app( tunnel_appname, { :name => tunnel_appname, :staging => {:framework => "sinatra"}, - :uris => ["#{tunnel_uniquename}.#{VMC::Cli::Config.suggest_url}"], + :uris => ["#{tunnel_uniquename}.#{target_base}"], :instances => 1, :resources => {:memory => 64}, :env => ["CALDECOTT_AUTH=#{token}"] } ) - Command::Apps.new(@options).send(:upload_app_bits, tunnel_appname, HELPER_APP) + apps_cmd.send(:upload_app_bits, tunnel_appname, HELPER_APP) invalidate_tunnel_app_info end def stop_caldecott - Command::Apps.new(@options).stop(tunnel_appname) + apps_cmd.stop(tunnel_appname) invalidate_tunnel_app_info end def start_caldecott - Command::Apps.new(@options).start(tunnel_appname) + apps_cmd.start(tunnel_appname) invalidate_tunnel_app_info + end + + private + + def apps_cmd + a = Command::Apps.new(@options) + a.client client + a end end end