2010-11-22 02:44:44 -05:00
|
|
|
module Fog
|
2011-06-15 17:26:43 -04:00
|
|
|
module Storage
|
|
|
|
class AWS
|
2010-11-22 02:44:44 -05:00
|
|
|
class Real
|
|
|
|
|
2011-11-14 04:41:40 -05:00
|
|
|
require 'fog/aws/requests/storage/acl_utils'
|
2011-08-24 21:19:55 -04:00
|
|
|
|
2010-11-22 02:44:44 -05:00
|
|
|
# Change access control list for an S3 object
|
|
|
|
#
|
2013-05-02 07:22:05 -04:00
|
|
|
# @param [String] bucket_name name of bucket to modify
|
|
|
|
# @param [String] object_name name of object to get access control list for
|
|
|
|
# @param [Hash] acl
|
2013-01-13 20:49:47 -05:00
|
|
|
# * Owner [Hash]
|
|
|
|
# * ID [String] id of owner
|
|
|
|
# * DisplayName [String] display name of owner
|
|
|
|
# * AccessControlList [Array]
|
|
|
|
# * Grantee [Hash]
|
|
|
|
# * DisplayName [String] Display name of grantee
|
|
|
|
# * ID [String] Id of grantee
|
2010-11-22 02:44:44 -05:00
|
|
|
# or
|
2013-01-13 20:49:47 -05:00
|
|
|
# * EmailAddress [String] Email address of grantee
|
2010-11-22 02:44:44 -05:00
|
|
|
# or
|
2013-01-13 20:49:47 -05:00
|
|
|
# * URI [String] URI of group to grant access for
|
|
|
|
# * Permission [String] Permission, in [FULL_CONTROL, WRITE, WRITE_ACP, READ, READ_ACP]
|
2013-05-02 07:22:05 -04:00
|
|
|
# @param [String] acl Permissions, must be in ['private', 'public-read', 'public-read-write', 'authenticated-read']
|
|
|
|
# @param [Hash] options
|
|
|
|
# @option options [String] versionId specify a particular version to retrieve
|
2010-11-22 02:44:44 -05:00
|
|
|
#
|
2013-01-13 20:49:47 -05:00
|
|
|
# @see http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTObjectPUTacl.html
|
2010-11-22 02:44:44 -05:00
|
|
|
|
|
|
|
def put_object_acl(bucket_name, object_name, acl, options = {})
|
|
|
|
query = {'acl' => nil}
|
|
|
|
if version_id = options.delete('versionId')
|
|
|
|
query['versionId'] = version_id
|
|
|
|
end
|
2011-08-23 10:24:11 -04:00
|
|
|
|
|
|
|
data = ""
|
|
|
|
headers = {}
|
|
|
|
|
|
|
|
if acl.is_a?(Hash)
|
2011-08-24 21:19:55 -04:00
|
|
|
data = Fog::Storage::AWS.hash_to_acl(acl)
|
2011-08-23 10:24:11 -04:00
|
|
|
else
|
|
|
|
if !['private', 'public-read', 'public-read-write', 'authenticated-read'].include?(acl)
|
|
|
|
raise Excon::Errors::BadRequest.new('invalid x-amz-acl')
|
|
|
|
end
|
|
|
|
headers['x-amz-acl'] = acl
|
|
|
|
end
|
2010-11-22 02:44:44 -05:00
|
|
|
|
2011-08-23 10:29:51 -04:00
|
|
|
headers['Content-MD5'] = Base64.encode64(Digest::MD5.digest(data)).strip
|
2011-08-23 10:24:11 -04:00
|
|
|
headers['Content-Type'] = 'application/json'
|
|
|
|
headers['Date'] = Fog::Time.now.to_date_header
|
|
|
|
|
2010-11-22 02:44:44 -05:00
|
|
|
request({
|
|
|
|
:body => data,
|
|
|
|
:expects => 200,
|
2011-08-23 10:24:11 -04:00
|
|
|
:headers => headers,
|
2013-04-12 06:31:10 -04:00
|
|
|
:bucket_name => bucket_name,
|
|
|
|
:object_name => object_name,
|
2010-11-22 02:44:44 -05:00
|
|
|
:method => 'PUT',
|
|
|
|
:query => query
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
2011-08-24 21:19:55 -04:00
|
|
|
|
|
|
|
class Mock
|
|
|
|
def put_object_acl(bucket_name, object_name, acl, options = {})
|
|
|
|
if acl.is_a?(Hash)
|
|
|
|
self.data[:acls][:object][bucket_name][object_name] = Fog::Storage::AWS.hash_to_acl(acl)
|
|
|
|
else
|
|
|
|
if !['private', 'public-read', 'public-read-write', 'authenticated-read'].include?(acl)
|
|
|
|
raise Excon::Errors::BadRequest.new('invalid x-amz-acl')
|
|
|
|
end
|
|
|
|
self.data[:acls][:object][bucket_name][object_name] = acl
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-11-22 02:44:44 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|