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

Merge pull request #1876 from soulcutter/restore-object-pr

Add POST object restore operation
This commit is contained in:
Wesley Beary 2013-06-10 15:29:48 -07:00
commit 2dd2a8b003
3 changed files with 65 additions and 2 deletions

View file

@ -0,0 +1,54 @@
module Fog
module Storage
class AWS
class Real
# Restore an object from Glacier to its original S3 path
#
# @param bucket_name [String] Name of bucket containing object
# @param object_name [String] Name of object to restore
# @option days [Integer] Number of days to restore object for. Defaults to 100000 (a very long time)
#
# @return [Excon::Response] response:
# * status [Integer] 200 (OK) Object is previously restored
# * status [Integer] 202 (Accepted) Object is not previously restored
# * status [Integer] 409 (Conflict) Restore is already in progress
#
# @see http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTObjectPOSTrestore.html
#
def post_object_restore(bucket_name, object_name, days = 100000)
raise ArgumentError.new('bucket_name is required') unless bucket_name
raise ArgumentError.new('object_name is required') unless object_name
data = '<RestoreRequest xmlns="http://s3.amazonaws.com/doc/2006-3-01"><Days>' + days.to_s + '</Days></RestoreRequest>'
headers = {}
headers['Content-MD5'] = Base64.encode64(Digest::MD5.digest(data)).strip
headers['Content-Type'] = 'application/xml'
headers['Date'] = Fog::Time.now.to_date_header
request({
:headers => headers,
:host => "#{bucket_name}.#{@host}",
:expects => [200, 202, 409],
:body => data,
:method => 'POST',
:query => {'restore' => nil},
:path => CGI.escape(object_name)
})
end
end
class Mock # :nodoc:all
def post_object_restore(bucket_name, object_name, days = 100000)
response = get_object(bucket_name, object_name)
response.body = nil
response
end
end
end
end
end

View file

@ -33,6 +33,7 @@ module Fog
response-content-language
response-content-type
response-expires
restore
torrent
uploadId
uploads
@ -87,6 +88,7 @@ module Fog
request :list_multipart_uploads
request :list_parts
request :post_object_hidden_fields
request :post_object_restore
request :put_bucket
request :put_bucket_acl
request :put_bucket_cors

View file

@ -46,6 +46,10 @@ Shindo.tests('AWS::Storage | object requests', ['aws']) do
Fog::Storage[:aws].head_object(@directory.identity, 'fog_object')
end
tests("#post_object_restore('#{@directory.identity}', 'fog_object')").succeeds do
Fog::Storage[:aws].post_object_restore(@directory.identity, 'fog_object')
end
tests("#put_object_acl('#{@directory.identity}', 'fog_object', 'private')").succeeds do
Fog::Storage[:aws].put_object_acl(@directory.identity, 'fog_object', 'private')
end
@ -160,6 +164,9 @@ Shindo.tests('AWS::Storage | object requests', ['aws']) do
Fog::Storage[:aws].put_object_acl('#{@directory.identity}', 'fog_object', 'invalid')
end
tests("#post_object_restore('#{@directory.identity}', 'fog_non_object')").raises(Excon::Errors::NotFound) do
Fog::Storage[:aws].post_object_restore(@directory.identity, 'fog_non_object')
end
end
@directory.destroy