You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by mf...@apache.org on 2010/11/08 09:34:07 UTC

svn commit: r1032493 - in /incubator/deltacloud/trunk/server: lib/sinatra/rabbit.rb server.rb

Author: mfojtik
Date: Mon Nov  8 08:34:06 2010
New Revision: 1032493

URL: http://svn.apache.org/viewvc?rev=1032493&view=rev
Log:
Add capability checking to rabbit and to key management initially.

Modified:
    incubator/deltacloud/trunk/server/lib/sinatra/rabbit.rb
    incubator/deltacloud/trunk/server/server.rb

Modified: incubator/deltacloud/trunk/server/lib/sinatra/rabbit.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/sinatra/rabbit.rb?rev=1032493&r1=1032492&r2=1032493&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/sinatra/rabbit.rb (original)
+++ incubator/deltacloud/trunk/server/lib/sinatra/rabbit.rb Mon Nov  8 08:34:06 2010
@@ -1,6 +1,7 @@
 require 'sinatra/base'
 require 'sinatra/url_for'
 require 'deltacloud/validation'
+require 'deltacloud/backend_capability'
 
 module Sinatra
 
@@ -13,6 +14,7 @@ module Sinatra
     class Operation
       attr_reader :name, :method
 
+      include ::Deltacloud::BackendCapability
       include ::Deltacloud::Validation
 
       STANDARD = {
@@ -58,6 +60,7 @@ module Sinatra
       def control(&block)
         op = self
         @control = Proc.new do
+          op.check_capability(driver)
           op.validate(params)
           instance_eval(&block)
         end

Modified: incubator/deltacloud/trunk/server/server.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/server.rb?rev=1032493&r1=1032492&r2=1032493&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/server.rb (original)
+++ incubator/deltacloud/trunk/server/server.rb Mon Nov  8 08:34:06 2010
@@ -32,6 +32,9 @@ error Deltacloud::Validation::Failure do
   report_error(400, "validation_failure")
 end
 
+error Deltacloud::BackendCapability::Failure do
+  report_error(405, "backend_capability_failure")
+end
 error Deltacloud::AuthException do
   report_error(403, "auth_exception")
 end
@@ -341,6 +344,7 @@ collection :keys do
 
   operation :index do
     description "List all available credentials which could be used for instance authentication."
+    with_capability :keys
     control do
       filter_all :keys
     end
@@ -348,18 +352,16 @@ collection :keys do
 
   operation :show do
     description "Show details about given instance credential."
+    with_capability :key
     param :id,  :string,  :required
     control { show :key }
   end
 
   operation :create do
     description "Create a new instance credential if backend supports this."
+    with_capability :create_key
     param :name,  :string,  :required
     control do
-      unless driver.respond_to?(:create_key)
-        raise Deltacloud::BackendFeatureUnsupported.new('501',
-          'Creating instance credentials is not supported in backend')
-      end
       @key = driver.create_key(credentials, { :key_name => params[:name] })
       respond_to do |format|
         format.html { haml :"keys/show" }
@@ -370,12 +372,9 @@ collection :keys do
 
   operation :destroy do
     description "Destroy given instance credential if backend supports this."
+    with_capability :destroy_key
     param :id,  :string,  :required
     control do
-      unless driver.respond_to?(:destroy_key)
-        raise Deltacloud::BackendFeatureUnsupported.new('501',
-          'Creating instance credentials is not supported in backend')
-      end
       driver.destroy_key(credentials, { :key_name => params[:id]})
       redirect(keys_url)
     end