Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add an api for CC, which returns a specific service offering

Get /services/v1/offerings/:label

Change-Id: I47e66278d0782e095b553cafbc904591e25b5571
  • Loading branch information...
commit bfd863d066c634685c0033e9b86c85ac080b83ed 1 parent a76a80b
Haipeng Wu authored
View
11 cloud_controller/app/controllers/services_controller.rb
@@ -7,7 +7,7 @@ class ServicesController < ApplicationController
include ServicesHelper
before_filter :validate_content_type
- before_filter :require_service_auth_token, :only => [:create, :delete, :update_handle, :list_handles, :list_brokered_services]
+ before_filter :require_service_auth_token, :only => [:create, :get, :delete, :update_handle, :list_handles, :list_brokered_services]
before_filter :require_user, :only => [:provision, :bind, :bind_external, :unbind, :unprovision,
:create_snapshot, :enum_snapshots, :snapshot_details,:rollback_snapshot, :delete_snapshot,
:serialized_url, :create_serialized_url, :import_from_url, :import_from_data, :job_info]
@@ -141,6 +141,15 @@ def list_brokered_services
render :json => {:brokered_services => result}
end
+ # Get a service offering on the CC
+ #
+ def get
+ svc = Service.find_by_label(params[:label])
+ raise CloudError.new(CloudError::SERVICE_NOT_FOUND) unless svc
+ raise CloudError.new(CloudError::FORBIDDEN) unless svc.verify_auth_token(@service_auth_token)
+ render :json => svc.hash_to_service_offering
+ end
+
# Unregister a service offering with the CC
#
def delete
View
17 cloud_controller/app/models/service.rb
@@ -160,4 +160,21 @@ def verify_auth_token(token)
(self.token == token)
end
end
+
+ def hash_to_service_offering
+ svc_offering = {
+ :label => self.label,
+ :url => self.url
+ }
+ svc_offering[:description] = self.description if self.description
+ svc_offering[:info_url] = self.info_url if self.info_url
+ svc_offering[:tags] = self.tags if self.tags
+ svc_offering[:plans] = self.plans if self.plans
+ svc_offering[:plan_options] = self.plan_options if self.plan_options
+ svc_offering[:binding_options] = self.binding_options if self.binding_options
+ svc_offering[:acls] = self.acls if self.acls
+ svc_offering[:active] = self.active if self.active
+ svc_offering[:timeout] = self.timeout if self.timeout
+ return svc_offering
+ end
end
View
1  cloud_controller/config/routes.rb
@@ -39,6 +39,7 @@
post 'services/v1/offerings' => 'services#create', :as => :service_create
delete 'services/v1/offerings/:label' => 'services#delete', :as => :service_delete, :label => /[^\/]+/
+ get 'services/v1/offerings/:label' => 'services#get', :as => :service_get, :label => /[^\/]+/
get 'services/v1/offerings/:label/handles' => 'services#list_handles', :as => :service_list_handles, :label => /[^\/]+/
post 'services/v1/offerings/:label/handles/:id' => 'services#update_handle', :as => :service_update_handle, :label => /[^\/]+/
post 'services/v1/configurations' => 'services#provision', :as => :service_provision
View
31 cloud_controller/spec/controllers/services_controller_spec.rb
@@ -221,6 +221,37 @@ def unbind_instance(service_id, handle_id, binding_options)
end
end
+ describe '#get' do
+ before :each do
+ @svc = Service.create(
+ :label => 'foo-bar',
+ :url => 'http://www.google.com',
+ :plans => ['free', 'nonfree'],
+ :token => 'foobar')
+ @svc.should be_valid
+ end
+
+ it 'should return not found for unknown services' do
+ get :get, :label => 'xxx'
+ response.status.should == 404
+ end
+
+ it 'should return not authorized on token mismatch' do
+ request.env['HTTP_X_VCAP_SERVICE_TOKEN'] = 'xxx'
+ get :get, :label => 'foo-bar'
+ response.status.should == 403
+ end
+
+ it 'should return the specific service offering' do
+ get :get, :label => 'foo-bar'
+ response.status.should == 200
+ resp = Yajl::Parser.parse(response.body)
+ resp["label"].should == 'foo-bar'
+ resp["url"].should == 'http://www.google.com'
+ resp["plans"].should == ['free', 'nonfree']
+ end
+ end
+
describe '#list_handles' do
it 'should return not found for unknown services' do
get :list_handles, :label => 'foo-bar'
Please sign in to comment.
Something went wrong with that request. Please try again.