1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[s3] add versioning support

This commit is contained in:
geemus 2010-05-10 20:28:27 -07:00
parent 7c0af34949
commit 013b2c3ead
7 changed files with 129 additions and 5 deletions

View file

@ -0,0 +1,24 @@
module Fog
module Parsers
module AWS
module S3
class GetBucketVersioning < Fog::Parsers::Base
def reset
@response = { 'VersioningConfiguration' => {} }
end
def end_element(name)
case name
when 'Status'
@response['VersioningConfiguration'][name] = @value
end
end
end
end
end
end
end

View file

@ -0,0 +1,43 @@
module Fog
module AWS
module S3
class Real
# Get versioning status for an S3 bucket
#
# ==== Parameters
# * bucket_name<~String> - name of bucket to get versioning status for
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'VersioningConfiguration'<~Hash>
# * Status<~String>: Versioning status in ['Enabled', 'Suspended', nil]
#
def get_bucket_versioning(bucket_name)
unless bucket_name
raise ArgumentError.new('bucket_name is required')
end
request({
:expects => 200,
:headers => {},
:host => "#{bucket_name}.#{@host}",
:idempotent => true,
:method => 'GET',
:parser => Fog::Parsers::AWS::S3::GetBucketVersioning.new,
:query => 'versioning'
})
end
end
class Mock
def get_bucket_versioning(bucket_name)
raise MockNotImplemented.new("Contributions welcome!")
end
end
end
end
end

View file

@ -14,6 +14,8 @@ module Fog
# * 'If-None-Match'<~String> - Returns object only if its etag differs from this value, otherwise returns 304 (Not Modified) # * 'If-None-Match'<~String> - Returns object only if its etag differs from this value, otherwise returns 304 (Not Modified)
# * 'If-Unmodified-Since'<~Time> - Returns object only if it has not been modified since this time, otherwise returns 412 (Precodition Failed). # * 'If-Unmodified-Since'<~Time> - Returns object only if it has not been modified since this time, otherwise returns 412 (Precodition Failed).
# * 'Range'<~String> - Range of object to download # * 'Range'<~String> - Range of object to download
# * 'versionId'<~String> - specify a particular version to retrieve
#
# ==== Returns # ==== Returns
# * response<~Excon::Response>: # * response<~Excon::Response>:
# * body<~String> - Contents of object # * body<~String> - Contents of object
@ -22,6 +24,7 @@ module Fog
# * 'Content-Type'<~String> - MIME type of object # * 'Content-Type'<~String> - MIME type of object
# * 'ETag'<~String> - Etag of object # * 'ETag'<~String> - Etag of object
# * 'Last-Modified'<~String> - Last modified timestamp for object # * 'Last-Modified'<~String> - Last modified timestamp for object
#
def get_object(bucket_name, object_name, options = {}, &block) def get_object(bucket_name, object_name, options = {}, &block)
unless bucket_name unless bucket_name
raise ArgumentError.new('bucket_name is required') raise ArgumentError.new('bucket_name is required')
@ -29,6 +32,7 @@ module Fog
unless object_name unless object_name
raise ArgumentError.new('object_name is required') raise ArgumentError.new('object_name is required')
end end
version_id = options.delete('versionId')
headers = {} headers = {}
headers['If-Modified-Since'] = options['If-Modified-Since'].utc.strftime("%a, %d %b %Y %H:%M:%S +0000") if options['If-Modified-Since'] headers['If-Modified-Since'] = options['If-Modified-Since'].utc.strftime("%a, %d %b %Y %H:%M:%S +0000") if options['If-Modified-Since']
headers['If-Unmodified-Since'] = options['If-Unmodified-Since'].utc.strftime("%a, %d %b %Y %H:%M:%S +0000") if options['If-Modified-Since'] headers['If-Unmodified-Since'] = options['If-Unmodified-Since'].utc.strftime("%a, %d %b %Y %H:%M:%S +0000") if options['If-Modified-Since']
@ -39,7 +43,8 @@ module Fog
:host => "#{bucket_name}.#{@host}", :host => "#{bucket_name}.#{@host}",
:idempotent => true, :idempotent => true,
:method => 'GET', :method => 'GET',
:path => CGI.escape(object_name) :path => CGI.escape(object_name),
:query => CGI.escape(version_id)
}, &block) }, &block)
end end

View file

@ -8,6 +8,8 @@ module Fog
# ==== Parameters # ==== Parameters
# * bucket_name<~String> - name of bucket containing object # * bucket_name<~String> - name of bucket containing object
# * object_name<~String> - name of object to get access control list for # * object_name<~String> - name of object to get access control list for
# * options<~Hash>:
# * 'versionId'<~String> - specify a particular version to retrieve
# #
# ==== Returns # ==== Returns
# * response<~Excon::Response>: # * response<~Excon::Response>:
@ -25,13 +27,17 @@ module Fog
# * 'URI'<~String> - URI of group to grant access for # * 'URI'<~String> - URI of group to grant access for
# * 'Permission'<~String> - Permission, in [FULL_CONTROL, WRITE, WRITE_ACP, READ, READ_ACP] # * 'Permission'<~String> - Permission, in [FULL_CONTROL, WRITE, WRITE_ACP, READ, READ_ACP]
# #
def get_object_acl(bucket_name, object_name) def get_object_acl(bucket_name, object_name, options = {})
unless bucket_name unless bucket_name
raise ArgumentError.new('bucket_name is required') raise ArgumentError.new('bucket_name is required')
end end
unless object_name unless object_name
raise ArgumentError.new('object_name is required') raise ArgumentError.new('object_name is required')
end end
query = 'acl'
if version_id = options.delete('versionId')
query << "&#{CGI.escape(version_id)}"
end
request({ request({
:expects => 200, :expects => 200,
:headers => {}, :headers => {},
@ -40,7 +46,7 @@ module Fog
:method => 'GET', :method => 'GET',
:parser => Fog::Parsers::AWS::S3::AccessControlList.new, :parser => Fog::Parsers::AWS::S3::AccessControlList.new,
:path => CGI.escape(object_name), :path => CGI.escape(object_name),
:query => 'acl' :query => query
}) })
end end

View file

@ -14,6 +14,7 @@ module Fog
# * 'If-None-Match'<~String> - Returns object only if its etag differs from this value, otherwise returns 304 (Not Modified) # * 'If-None-Match'<~String> - Returns object only if its etag differs from this value, otherwise returns 304 (Not Modified)
# * 'If-Unmodified-Since'<~Time> - Returns object only if it has not been modified since this time, otherwise returns 412 (Precodition Failed). # * 'If-Unmodified-Since'<~Time> - Returns object only if it has not been modified since this time, otherwise returns 412 (Precodition Failed).
# * 'Range'<~String> - Range of object to download # * 'Range'<~String> - Range of object to download
# * 'versionId'<~String> - specify a particular version to retrieve
# #
# ==== Returns # ==== Returns
# * response<~Excon::Response>: # * response<~Excon::Response>:
@ -24,6 +25,7 @@ module Fog
# * 'ETag'<~String> - Etag of object # * 'ETag'<~String> - Etag of object
# * 'Last-Modified'<~String> - Last modified timestamp for object # * 'Last-Modified'<~String> - Last modified timestamp for object
def head_object(bucket_name, object_name, options={}) def head_object(bucket_name, object_name, options={})
version_id = options.delete('versionId')
headers = {} headers = {}
headers['If-Modified-Since'] = options['If-Modified-Since'].utc.strftime("%a, %d %b %Y %H:%M:%S +0000") if options['If-Modified-Since'] headers['If-Modified-Since'] = options['If-Modified-Since'].utc.strftime("%a, %d %b %Y %H:%M:%S +0000") if options['If-Modified-Since']
headers['If-Unmodified-Since'] = options['If-Unmodified-Since'].utc.strftime("%a, %d %b %Y %H:%M:%S +0000") if options['If-Modified-Since'] headers['If-Unmodified-Since'] = options['If-Unmodified-Since'].utc.strftime("%a, %d %b %Y %H:%M:%S +0000") if options['If-Modified-Since']
@ -33,7 +35,8 @@ module Fog
:headers => headers, :headers => headers,
:host => "#{bucket_name}.#{@host}", :host => "#{bucket_name}.#{@host}",
:method => 'HEAD', :method => 'HEAD',
:path => CGI.escape(object_name) :path => CGI.escape(object_name),
:query => CGI.escape(version_id)
}) })
end end

View file

@ -0,0 +1,40 @@
module Fog
module AWS
module S3
class Real
# Change versioning status for an S3 bucket
#
# ==== Parameters
# * bucket_name<~String> - name of bucket to modify
# * status<~String> - Status to change to in ['Enabled', 'Suspended']
def put_bucket_versioning(bucket_name, status)
data =
<<-DATA
<VersioningConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<Status>#{status}</Status>
</VersioningConfiguration>
DATA
request({
:body => data,
:expects => 200,
:headers => {},
:host => "#{bucket_name}.#{@host}",
:method => 'PUT',
:query => 'versioning'
})
end
end
class Mock
def put_bucket_versioning(bucket_name, status)
raise MockNotImplemented.new("Contributions welcome!")
end
end
end
end
end

View file

@ -13,6 +13,7 @@ module Fog
require 'fog/aws/parsers/s3/copy_object' require 'fog/aws/parsers/s3/copy_object'
require 'fog/aws/parsers/s3/get_bucket' require 'fog/aws/parsers/s3/get_bucket'
require 'fog/aws/parsers/s3/get_bucket_location' require 'fog/aws/parsers/s3/get_bucket_location'
require 'fog/aws/parsers/s3/get_bucket_versioning'
require 'fog/aws/parsers/s3/get_request_payment' require 'fog/aws/parsers/s3/get_request_payment'
require 'fog/aws/parsers/s3/get_service' require 'fog/aws/parsers/s3/get_service'
require 'fog/aws/requests/s3/copy_object' require 'fog/aws/requests/s3/copy_object'
@ -21,6 +22,7 @@ module Fog
require 'fog/aws/requests/s3/get_bucket' require 'fog/aws/requests/s3/get_bucket'
require 'fog/aws/requests/s3/get_bucket_acl' require 'fog/aws/requests/s3/get_bucket_acl'
require 'fog/aws/requests/s3/get_bucket_location' require 'fog/aws/requests/s3/get_bucket_location'
require 'fog/aws/requests/s3/get_bucket_versioning'
require 'fog/aws/requests/s3/get_object' require 'fog/aws/requests/s3/get_object'
require 'fog/aws/requests/s3/get_object_acl' require 'fog/aws/requests/s3/get_object_acl'
require 'fog/aws/requests/s3/get_object_torrent' require 'fog/aws/requests/s3/get_object_torrent'
@ -30,6 +32,7 @@ module Fog
require 'fog/aws/requests/s3/head_object' require 'fog/aws/requests/s3/head_object'
require 'fog/aws/requests/s3/put_bucket' require 'fog/aws/requests/s3/put_bucket'
require 'fog/aws/requests/s3/put_bucket_acl' require 'fog/aws/requests/s3/put_bucket_acl'
require 'fog/aws/requests/s3/put_bucket_versioning'
require 'fog/aws/requests/s3/put_object' require 'fog/aws/requests/s3/put_object'
require 'fog/aws/requests/s3/put_request_payment' require 'fog/aws/requests/s3/put_request_payment'
@required = true @required = true
@ -195,7 +198,7 @@ DATA
canonical_resource << "#{CGI.escape(subdomain).downcase}/" canonical_resource << "#{CGI.escape(subdomain).downcase}/"
end end
canonical_resource << "#{params[:path]}" canonical_resource << "#{params[:path]}"
if ['acl', 'location', 'logging', 'requestPayment', 'torrent'].include?(params[:query]) if params[:query]
canonical_resource << "?#{params[:query]}" canonical_resource << "?#{params[:query]}"
end end
string_to_sign << "#{canonical_resource}" string_to_sign << "#{canonical_resource}"