Skip to content

Instantly share code, notes, and snippets.

@hamakn
Created May 15, 2012 14:25
Show Gist options
  • Save hamakn/2702159 to your computer and use it in GitHub Desktop.
Save hamakn/2702159 to your computer and use it in GitHub Desktop.
show service environment (id, pw, host, dbname)
require 'rubygems' # for ruby18
require 'sinatra'
require 'json'
require 'yaml'
get '/' do
"<h1>Hello Tamac.io!!</h1>"
end
get '/version' do
"Ruby version: #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
end
get '/env' do
ENV.map { |key, value| "#{key}: #{value}" }.join("<br/>")
end
get '/service-env' do
content_type 'text'
JSON.parse(ENV["VCAP_SERVICES"]).inject({}) do |output, item|
service_tag = item.first
service_array = item.last
service_array.each do |instance|
output[instance["name"]] = {
"adapter" => service_tag,
"hostname" => instance["credentials"]["host"],
"database" => instance["credentials"]["name"],
"username" => instance["credentials"]["user"],
"password" => instance["credentials"]["password"],
}
end
output
end.to_yaml
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment