Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/cli/commands/services.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
29 changes: 29 additions & 0 deletions lib/cli/tunnel_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down