You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by ma...@redhat.com on 2010/08/13 23:30:13 UTC

['PATCH' 2/3] basic blobstore functions - collections, respond_to hack [2/3 one more follows]

From: marios <ma...@redhat.com>

---
 server/lib/sinatra/respond_to.rb |    3 +-
 server/server.rb                 |   39 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+), 1 deletions(-)

diff --git a/server/lib/sinatra/respond_to.rb b/server/lib/sinatra/respond_to.rb
index f4704ea..f87628e 100644
--- a/server/lib/sinatra/respond_to.rb
+++ b/server/lib/sinatra/respond_to.rb
@@ -43,7 +43,8 @@ module Sinatra
       app.before do
         # Let through sinatra image urls in development
         next if self.class.development? && request.path_info =~ %r{/__sinatra__/.*?.png}
-
+        next if request.path_info =~ (/\/api\/containers\/*/)
+        
         unless options.static? && options.public? && (request.get? || request.head?) && static_file?(request.path_info)
           rpi = request.path_info.sub(%r{\.([^\./]+)$}, '')
 
diff --git a/server/server.rb b/server/server.rb
index 1373fa3..e0a61c1 100644
--- a/server/server.rb
+++ b/server/server.rb
@@ -352,3 +352,42 @@ collection :keys do
   end
 
 end
+
+VALID_RESPONSE_FORMATS = ['xml', 'XML', 'html', 'HTML', 'json', 'JSON']
+#--
+#*  F  *  I  *  X  *  M  *  E - will ultimately use Accept header to do this
+#--
+get '/api/containers/:container/:blob' do
+  response_format = params['format'] unless (params['format'].nil? || !VALID_RESPONSE_FORMATS.include?(params['format']))
+  response_format ||= 'html'
+  @blob = driver.blob(credentials, { :id => params[:blob], 'container' => params[:container]})
+  if @blob 
+    respond_to do |format|
+      case response_format
+        when /html/i then format.html { haml :'blobs/show' }
+        when /xml/i then format.xml { haml :'blobs/show' }
+        when /json/i then format.json { convert_to_json(blobs, @blob) }
+      end
+    end
+  else
+      report_error(404, 'not_found')
+  end
+end
+
+collection :containers do
+  description "Cloud Storage Containers - aka buckets|directories|folders"
+
+  operation :index do
+    description "List containers associated with this account" 
+    param :id,        :string
+    param :name,      :string
+    param :size,      :string
+    control { filter_all(:containers) }
+  end
+  
+  operation :show do
+    description "Show container"
+    param :id,        :string
+    control { show(:container) }
+  end
+end
\ No newline at end of file
-- 
1.7.2.1