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..b010ee6 100644 --- a/lib/cli/tunnel_helper.rb +++ b/lib/cli/tunnel_helper.rb @@ -199,7 +199,36 @@ 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