You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by Tobias Crawley <tc...@redhat.com> on 2010/11/04 14:51:20 UTC
[PATCH 2/3] Add capability checking to rabbit and to key management initially.
---
server/lib/sinatra/rabbit.rb | 3 +++
server/server.rb | 15 +++++++--------
2 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/server/lib/sinatra/rabbit.rb b/server/lib/sinatra/rabbit.rb
index f411268..94c74e3 100644
--- a/server/lib/sinatra/rabbit.rb
+++ b/server/lib/sinatra/rabbit.rb
@@ -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
diff --git a/server/server.rb b/server/server.rb
index af8bc09..7e226a8 100644
--- a/server/server.rb
+++ b/server/server.rb
@@ -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
@@ -324,6 +327,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
@@ -331,18 +335,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" }
@@ -353,12 +355,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
--
1.7.2.3