deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject git commit: Core: Fixed broken listing of supported collections due to bug in capability checking
Date Wed, 11 Jul 2012 11:19:55 GMT
Updated Branches:
  refs/heads/master 3202650f9 -> 57b8272a3


Core: Fixed broken listing of supported collections due to bug in capability checking

Signed-off-by: Michal fojtik <mfojtik@redhat.com>


Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/57b8272a
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/57b8272a
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/57b8272a

Branch: refs/heads/master
Commit: 57b8272a35a21157238ff957320784aff6f7f8fb
Parents: 3202650
Author: Michal Fojtik <mfojtik@redhat.com>
Authored: Wed Jul 11 11:13:47 2012 +0200
Committer: Michal fojtik <mfojtik@redhat.com>
Committed: Wed Jul 11 13:20:45 2012 +0200

----------------------------------------------------------------------
 server/lib/deltacloud/helpers/deltacloud_helper.rb |   13 +++++++++++++
 server/lib/deltacloud/server.rb                    |    2 +-
 server/views/api/show.html.haml                    |    3 +--
 server/views/api/show.xml.haml                     |    3 +--
 4 files changed, 16 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/57b8272a/server/lib/deltacloud/helpers/deltacloud_helper.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/helpers/deltacloud_helper.rb b/server/lib/deltacloud/helpers/deltacloud_helper.rb
index de28590..cec22ac 100644
--- a/server/lib/deltacloud/helpers/deltacloud_helper.rb
+++ b/server/lib/deltacloud/helpers/deltacloud_helper.rb
@@ -18,6 +18,19 @@ module Deltacloud::Helpers
 
     require 'benchmark'
 
+    def supported_collections
+      Deltacloud::Collections.deltacloud_modules.each do |m|
+        m.collections.each do |c|
+          # Get the required capability for the :index operation (like 'realms' or 'instance_state_machine')
+          index_operation_capability = c.operation(:index).required_capability
+          # Then use this capability to check if the 'capability' lambda defined
+          # for the Sinatra::Base class evaluate to 'true'
+          next if m.settings.respond_to?(:capability) and !m.settings.capability(index_operation_capability)
+          yield c if block_given?
+        end
+      end
+    end
+
     def auth_feature_name
       return 'key' if driver.class.has_feature?(:instances, :authentication_key)
       return 'password' if driver.class.has_feature?(:instances, :authentication_password)

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/57b8272a/server/lib/deltacloud/server.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/server.rb b/server/lib/deltacloud/server.rb
index 10af202..d842c62 100644
--- a/server/lib/deltacloud/server.rb
+++ b/server/lib/deltacloud/server.rb
@@ -56,7 +56,7 @@ module Deltacloud
     end
 
     options Deltacloud.config[:deltacloud].root_url + '/?' do
-      headers 'Allow' => Deltacloud.collections.select { |c| driver.respond_to?(c.collection_name)
}.map { |c| c.collection_name }.join(',')
+      headers 'Allow' => supported_collections { |c| c.collection_name }.join(',')
     end
 
     post Deltacloud.config[:deltacloud].root_url + '/?' do

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/57b8272a/server/views/api/show.html.haml
----------------------------------------------------------------------
diff --git a/server/views/api/show.html.haml b/server/views/api/show.html.haml
index ef666d8..d315ebb 100644
--- a/server/views/api/show.html.haml
+++ b/server/views/api/show.html.haml
@@ -3,8 +3,7 @@
 
 %div{ :'data-role' => :content, :'data-theme' => 'c'}
   %ul{ :'data-role' => :listview, :'data-inset' => 'true'}
-    - Deltacloud.collections.each do |c|
-      - next unless c.operation(:index).has_capability?
+    - supported_collections do |c|
       %li
         %a{ :href => api_url_for(c.collection_name),  :'data-icon' => "arrow-r"}=c.collection_name.to_s.gsub('_',
' ').titlecase
 

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/57b8272a/server/views/api/show.xml.haml
----------------------------------------------------------------------
diff --git a/server/views/api/show.xml.haml b/server/views/api/show.xml.haml
index 4ba8168..73e7171 100644
--- a/server/views/api/show.xml.haml
+++ b/server/views/api/show.xml.haml
@@ -1,6 +1,5 @@
 %api{ :version => settings.version, :driver => driver_symbol, :provider => Thread.current[:provider]
|| ENV['API_PROVIDER'] }
-  - Deltacloud.collections.each do |c|
-    - next unless c.operation(:index).has_capability?
+  - supported_collections do |c|
     %link{ :rel => c.collection_name, :href => self.send(:"#{c.collection_name}_url")}
       - c.features.select { |f| driver.class.has_feature?(c.collection_name, f.name) }.each
do |f|
         %feature{ :name => f.name }


Mime
View raw message