Permalink
Browse files

OAuth2 service tests updated to support CCNGv2

  • Loading branch information...
1 parent 48d78b2 commit 34eaa4619138687cfb3be75ba348a41fd23b3df4 David Stevenson committed Mar 14, 2013
Showing with 8 additions and 4 deletions.
  1. +5 −4 sinatra/oauth2_app/app.rb
  2. +3 −0 sinatra/oauth2_app/config.ru
View
9 sinatra/oauth2_app/app.rb
@@ -3,7 +3,7 @@
require 'yajl'
require 'omniauth-uaa-oauth2'
require 'restclient'
-
+
enable :sessions
config = {}
@@ -16,7 +16,8 @@
services = JSON.parse(ENV['VCAP_SERVICES']||"{}", :symbolize_keys=>true)
if services[SERVICE_LABEL] && services[SERVICE_LABEL].length>0
config.merge!(services[SERVICE_LABEL][0][:credentials])
- config[:cloud_controller] = config[:auth_server_url].sub(/\/\/[^.]*\./,"//api.") if config[:auth_server_url]
+ prefix = ENV["PORT"] ? 'ccng' : 'api'
+ config[:cloud_controller] = config[:auth_server_url].sub(/\/\/[^.]*\./,"//#{prefix}.") if config[:auth_server_url]
end
puts "Config: #{config.inspect}"
@@ -65,14 +66,14 @@
</html>
HTML
end
-
+
get '/apps' do
token = session[:auth][:credentials][:token]
apps = JSON.parse(RestClient.get("#{config[:cloud_controller]}/apps", :authorization=>"#{token}"), :symbolize_keys=>true)
tree = ""
apps.each do |app|
body = ""
- app.each do |k,v|
+ app.each do |k,v|
body << "<li>#{k}: #{v}</li>"
end
tree << "<li>#{app[:name]}<ul>#{body}</ul></li>"
View
3 sinatra/oauth2_app/config.ru
@@ -0,0 +1,3 @@
+require "./app"
+run Sinatra::Application
+

0 comments on commit 34eaa46

Please sign in to comment.