Skip to content

Commit

Permalink
Add post_object_restore support
Browse files Browse the repository at this point in the history
  • Loading branch information
soulcutter committed Jun 10, 2013
1 parent 47a1a93 commit 2c23e25
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
54 changes: 54 additions & 0 deletions lib/fog/aws/requests/storage/post_object_restore.rb
@@ -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
#
# @see http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTObjectPOSTrestore.html
#
def post_object_restore(bucket_name, object_name, days = 100000)
unless bucket_name
raise ArgumentError.new('bucket_name is required')
end
unless object_name
raise ArgumentError.new('object_name is required')
end

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}",
:expect => 202,
: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)
raise "TODO"
end

end
end
end
end
6 changes: 4 additions & 2 deletions lib/fog/aws/storage.rb
Expand Up @@ -33,6 +33,7 @@ class AWS < Fog::Service
response-content-language
response-content-type
response-expires
restore
torrent
uploadId
uploads
Expand Down Expand Up @@ -87,6 +88,7 @@ class AWS < Fog::Service
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
Expand Down Expand Up @@ -217,7 +219,7 @@ def request_params(params)
:path => path,
:headers => headers,
})

#
ret.delete(:path_style)
ret.delete(:bucket_name)
Expand Down Expand Up @@ -490,7 +492,7 @@ def request(params, &block)

expires = Fog::Time.now.to_date_header
signature = signature(params, expires)

params = request_params(params)
params.delete(:port) unless params[:port]

Expand Down

0 comments on commit 2c23e25

Please sign in to comment.