From 1274aa63232740a3308e6d935318b681c7851a33 Mon Sep 17 00:00:00 2001 From: Arlo Carreon Date: Thu, 10 Jan 2013 11:44:51 -0500 Subject: [PATCH 1/2] Exporting VCAP_SERVICES data locally --- lib/cli/commands/services.rb | 7 +++++++ lib/cli/tunnel_helper.rb | 30 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/lib/cli/commands/services.rb b/lib/cli/commands/services.rb index 976300c..d5a8517 100644 --- a/lib/cli/commands/services.rb +++ b/lib/cli/commands/services.rb @@ -184,6 +184,13 @@ def tunnel(service=nil, client_name=nil) conn_info = tunnel_connection_info info[:vendor], service, auth, infra_name display_tunnel_connection_info(conn_info) + + if Process.uid == 0 + write_vcap_variable_locally(conn_info,port,info) + else + display "For VCAP_SERVICES variable locally use: sudo af tunnel".green + end + display "Starting tunnel to #{service.bold} on port #{port.to_s.bold}." start_tunnel(port, conn_info, auth, infra_name) diff --git a/lib/cli/tunnel_helper.rb b/lib/cli/tunnel_helper.rb index 1d373c3..e273a7e 100644 --- a/lib/cli/tunnel_helper.rb +++ b/lib/cli/tunnel_helper.rb @@ -199,7 +199,37 @@ def start_tunnel(local_port, conn_info, auth, infra) at_exit { @local_tunnel_thread.kill } end + def write_vcap_variable_locally(info, port, service) + # Collect our variables + user = info['user'] || info['username'] + port = port + host = "127.0.0.1" + pass = info['password'] + name = info['name'] + + # Create service key. Mimicing VCAP_SERVICES ENV variable + serviceKey = service[:vendor] + "-" + service[:version] + + # Create our, soon to be, JSON object + json = {} + json[serviceKey] = [nil] + json[serviceKey][0] = { + :credentials => { + :name => name, + :port => port, + :password => pass, + :user => user, + :username => user, + :host => host, + :hostname => host + } + } + + # Show the user that VCAP_SERVICES JSON data will be available + display "Writing JSON DB Info to /etc/af_vcap_services".green + system("sudo echo '"+json.to_hash.to_json+"' > /etc/af_vcap_services") + end def pick_tunnel_port(port) original = port From 5acd30c2e86b79468a6839dd4d796806cebba57f Mon Sep 17 00:00:00 2001 From: Arlo Carreon Date: Thu, 10 Jan 2013 11:48:59 -0500 Subject: [PATCH 2/2] Fixing whitespace --- lib/cli/tunnel_helper.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/cli/tunnel_helper.rb b/lib/cli/tunnel_helper.rb index e273a7e..b010ee6 100644 --- a/lib/cli/tunnel_helper.rb +++ b/lib/cli/tunnel_helper.rb @@ -228,7 +228,6 @@ def write_vcap_variable_locally(info, port, service) # Show the user that VCAP_SERVICES JSON data will be available display "Writing JSON DB Info to /etc/af_vcap_services".green system("sudo echo '"+json.to_hash.to_json+"' > /etc/af_vcap_services") - end def pick_tunnel_port(port)