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:
parent
7c0af34949
commit
013b2c3ead
7 changed files with 129 additions and 5 deletions
24
lib/fog/aws/parsers/s3/get_bucket_versioning.rb
Normal file
24
lib/fog/aws/parsers/s3/get_bucket_versioning.rb
Normal 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
|
43
lib/fog/aws/requests/s3/get_bucket_versioning.rb
Normal file
43
lib/fog/aws/requests/s3/get_bucket_versioning.rb
Normal 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
|
|
@ -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-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
|
||||
# * 'versionId'<~String> - specify a particular version to retrieve
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~String> - Contents of object
|
||||
|
@ -22,6 +24,7 @@ module Fog
|
|||
# * 'Content-Type'<~String> - MIME type of object
|
||||
# * 'ETag'<~String> - Etag of object
|
||||
# * 'Last-Modified'<~String> - Last modified timestamp for object
|
||||
#
|
||||
def get_object(bucket_name, object_name, options = {}, &block)
|
||||
unless bucket_name
|
||||
raise ArgumentError.new('bucket_name is required')
|
||||
|
@ -29,6 +32,7 @@ module Fog
|
|||
unless object_name
|
||||
raise ArgumentError.new('object_name is required')
|
||||
end
|
||||
version_id = options.delete('versionId')
|
||||
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-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}",
|
||||
:idempotent => true,
|
||||
:method => 'GET',
|
||||
:path => CGI.escape(object_name)
|
||||
:path => CGI.escape(object_name),
|
||||
:query => CGI.escape(version_id)
|
||||
}, &block)
|
||||
end
|
||||
|
||||
|
|
|
@ -8,6 +8,8 @@ module Fog
|
|||
# ==== Parameters
|
||||
# * bucket_name<~String> - name of bucket containing object
|
||||
# * object_name<~String> - name of object to get access control list for
|
||||
# * options<~Hash>:
|
||||
# * 'versionId'<~String> - specify a particular version to retrieve
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
|
@ -25,13 +27,17 @@ module Fog
|
|||
# * 'URI'<~String> - URI of group to grant access for
|
||||
# * '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
|
||||
raise ArgumentError.new('bucket_name is required')
|
||||
end
|
||||
unless object_name
|
||||
raise ArgumentError.new('object_name is required')
|
||||
end
|
||||
query = 'acl'
|
||||
if version_id = options.delete('versionId')
|
||||
query << "&#{CGI.escape(version_id)}"
|
||||
end
|
||||
request({
|
||||
:expects => 200,
|
||||
:headers => {},
|
||||
|
@ -40,7 +46,7 @@ module Fog
|
|||
:method => 'GET',
|
||||
:parser => Fog::Parsers::AWS::S3::AccessControlList.new,
|
||||
:path => CGI.escape(object_name),
|
||||
:query => 'acl'
|
||||
:query => query
|
||||
})
|
||||
end
|
||||
|
||||
|
|
|
@ -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-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
|
||||
# * 'versionId'<~String> - specify a particular version to retrieve
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
|
@ -24,6 +25,7 @@ module Fog
|
|||
# * 'ETag'<~String> - Etag of object
|
||||
# * 'Last-Modified'<~String> - Last modified timestamp for object
|
||||
def head_object(bucket_name, object_name, options={})
|
||||
version_id = options.delete('versionId')
|
||||
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-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,
|
||||
:host => "#{bucket_name}.#{@host}",
|
||||
:method => 'HEAD',
|
||||
:path => CGI.escape(object_name)
|
||||
:path => CGI.escape(object_name),
|
||||
:query => CGI.escape(version_id)
|
||||
})
|
||||
end
|
||||
|
||||
|
|
40
lib/fog/aws/requests/s3/put_bucket_versioning.rb
Normal file
40
lib/fog/aws/requests/s3/put_bucket_versioning.rb
Normal 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
|
|
@ -13,6 +13,7 @@ module Fog
|
|||
require 'fog/aws/parsers/s3/copy_object'
|
||||
require 'fog/aws/parsers/s3/get_bucket'
|
||||
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_service'
|
||||
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_acl'
|
||||
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_acl'
|
||||
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/put_bucket'
|
||||
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_request_payment'
|
||||
@required = true
|
||||
|
@ -195,7 +198,7 @@ DATA
|
|||
canonical_resource << "#{CGI.escape(subdomain).downcase}/"
|
||||
end
|
||||
canonical_resource << "#{params[:path]}"
|
||||
if ['acl', 'location', 'logging', 'requestPayment', 'torrent'].include?(params[:query])
|
||||
if params[:query]
|
||||
canonical_resource << "?#{params[:query]}"
|
||||
end
|
||||
string_to_sign << "#{canonical_resource}"
|
||||
|
|
Loading…
Reference in a new issue