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/09/20 20:52:19 UTC
['PATCH' 4/4] Adds buckets collection to server.rb and other changes for blobstore api
From: marios <ma...@redhat.com>
---
server/lib/sinatra/respond_to.rb | 2 +
server/server.rb | 82 ++++++++++++++++++++++++++++++++++++++
2 files changed, 84 insertions(+), 0 deletions(-)
diff --git a/server/lib/sinatra/respond_to.rb b/server/lib/sinatra/respond_to.rb
index f4704ea..829cbe8 100644
--- a/server/lib/sinatra/respond_to.rb
+++ b/server/lib/sinatra/respond_to.rb
@@ -43,6 +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}
+ #FIXME using ?format to do content negotiation for buckets so skip negotiation here?
+ next if request.path_info =~ (/\/api\/buckets\/*/)
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 498d3ed..f19c213 100644
--- a/server/server.rb
+++ b/server/server.rb
@@ -9,6 +9,7 @@ require 'sinatra/lazy_auth'
require 'erb'
require 'haml'
require 'open3'
+require 'lib/deltacloud/helpers/blob_stream'
configure do
set :raise_errors => false
@@ -355,3 +356,84 @@ 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/buckets/:bucket/: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], 'bucket' => params[:bucket]})
+ 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
+
+get '/api/buckets/new' do
+ respond_to do |format|
+ format.html { haml :"buckets/new" }
+ end
+end
+
+
+get '/api/buckets/:bucket/:blob/content' do
+ BlobStream.call(env, credentials, params)
+end
+
+collection :buckets do
+ description "Cloud Storage buckets - aka buckets|directories|folders"
+
+ operation :index do
+ description "List buckets associated with this account"
+ param :id, :string
+ param :name, :string
+ param :size, :string
+ control { filter_all(:buckets) }
+ end
+
+ operation :show do
+ description "Show bucket"
+ param :id, :string
+ control { show(:bucket) }
+ end
+
+ operation :create do
+ description "Create a new bucket (POST /api/buckets)"
+ param :name, :string, :required
+ control do
+ @bucket = driver.create_bucket(credentials, params[:name], params)
+ respond_to do |format|
+ format.xml do
+ response.status = 201 # Created
+ response['Location'] = bucket_url(@bucket.id)
+ haml :"buckets/show"
+ end
+ format.html do
+ redirect bucket_url(@bucket.id) if @bucket and @bucket.id
+ redirect buckets_url
+ end
+ end
+ end
+ end
+
+ operation :destroy do
+ description "Delete a bucket by name - bucket must be empty"
+ param :id, :string, :required
+ control do
+ driver.delete_bucket(credentials, params[:id], params)
+ redirect(buckets_url)
+ end
+ end
+
+end
+
+
--
1.7.2.3
Re: ['PATCH' 4/4] Adds buckets collection to server.rb and other
changes for blobstore api
Posted by "marios@redhat.com" <ma...@redhat.com>.
Hi David - got rid of all this stuff from server.rb. Michal had put the
relevant code into respond_to but forgot to push. Its now there in svn
commit: r1000397,
marios
On 23/09/10 00:26, David Lutterkort wrote:
> On Mon, 2010-09-20 at 19:52 +0100, mandreou@redhat.com wrote:
>> From: marios<ma...@redhat.com>
>>
>> ---
>> server/lib/sinatra/respond_to.rb | 2 +
>> server/server.rb | 82 ++++++++++++++++++++++++++++++++++++++
>> 2 files changed, 84 insertions(+), 0 deletions(-)
>>
>> diff --git a/server/lib/sinatra/respond_to.rb b/server/lib/sinatra/respond_to.rb
>> index f4704ea..829cbe8 100644
>> --- a/server/lib/sinatra/respond_to.rb
>> +++ b/server/lib/sinatra/respond_to.rb
>> @@ -43,6 +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}
>> + #FIXME using ?format to do content negotiation for buckets so skip negotiation here?
>> + next if request.path_info =~ (/\/api\/buckets\/*/)
>
> I'd prefer if we changed respond_to so that it never uses the extension
> on the URL path's basename to indicate content; instead, use a query
> parameter like '?format=xml' to override the Accept header.
>
> Overriding Accept is mostly a convenience for humans (e.g., to look at
> XML in a browser)
>
>> diff --git a/server/server.rb b/server/server.rb
>> index 498d3ed..f19c213 100644
>> --- a/server/server.rb
>> +++ b/server/server.rb
>> @@ -9,6 +9,7 @@ require 'sinatra/lazy_auth'
>> require 'erb'
>> require 'haml'
>> require 'open3'
>> +require 'lib/deltacloud/helpers/blob_stream'
>>
>> configure do
>> set :raise_errors => false
>> @@ -355,3 +356,84 @@ 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/buckets/:bucket/:blob' do
>> + response_format = params['format'] unless (params['format'].nil? || !VALID_RESPONSE_FORMATS.include?(params['format']))
>> + response_format ||= 'html'
>
> This should just go into respond_to
>
> David
>
>
Re: ['PATCH' 4/4] Adds buckets collection to server.rb and other
changes for blobstore api
Posted by David Lutterkort <lu...@redhat.com>.
On Mon, 2010-09-20 at 19:52 +0100, mandreou@redhat.com wrote:
> From: marios <ma...@redhat.com>
>
> ---
> server/lib/sinatra/respond_to.rb | 2 +
> server/server.rb | 82 ++++++++++++++++++++++++++++++++++++++
> 2 files changed, 84 insertions(+), 0 deletions(-)
>
> diff --git a/server/lib/sinatra/respond_to.rb b/server/lib/sinatra/respond_to.rb
> index f4704ea..829cbe8 100644
> --- a/server/lib/sinatra/respond_to.rb
> +++ b/server/lib/sinatra/respond_to.rb
> @@ -43,6 +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}
> + #FIXME using ?format to do content negotiation for buckets so skip negotiation here?
> + next if request.path_info =~ (/\/api\/buckets\/*/)
I'd prefer if we changed respond_to so that it never uses the extension
on the URL path's basename to indicate content; instead, use a query
parameter like '?format=xml' to override the Accept header.
Overriding Accept is mostly a convenience for humans (e.g., to look at
XML in a browser)
> diff --git a/server/server.rb b/server/server.rb
> index 498d3ed..f19c213 100644
> --- a/server/server.rb
> +++ b/server/server.rb
> @@ -9,6 +9,7 @@ require 'sinatra/lazy_auth'
> require 'erb'
> require 'haml'
> require 'open3'
> +require 'lib/deltacloud/helpers/blob_stream'
>
> configure do
> set :raise_errors => false
> @@ -355,3 +356,84 @@ 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/buckets/:bucket/:blob' do
> + response_format = params['format'] unless (params['format'].nil? || !VALID_RESPONSE_FORMATS.include?(params['format']))
> + response_format ||= 'html'
This should just go into respond_to
David