2010-11-22 15:44:44 +08:00
|
|
|
module Fog
|
2011-06-15 14:26:43 -07:00
|
|
|
module Storage
|
|
|
|
class AWS
|
2010-11-22 15:44:44 +08:00
|
|
|
class Real
|
|
|
|
|
2011-11-14 10:41:40 +01:00
|
|
|
require 'fog/aws/requests/storage/acl_utils'
|
2011-08-24 21:19:55 -04:00
|
|
|
|
2010-11-22 15:44:44 +08:00
|
|
|
# Change access control list for an S3 object
|
|
|
|
#
|
2013-01-13 19:49:47 -06:00
|
|
|
# @param bucket_name [String] name of bucket to modify
|
|
|
|
# @param object_name [String] name of object to get access control list for
|
|
|
|
# @param acl [Hash]:
|
|
|
|
# * 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 15:44:44 +08:00
|
|
|
# or
|
2013-01-13 19:49:47 -06:00
|
|
|
# * EmailAddress [String] Email address of grantee
|
2010-11-22 15:44:44 +08:00
|
|
|
# or
|
2013-01-13 19:49:47 -06:00
|
|
|
# * URI [String] URI of group to grant access for
|
|
|
|
# * Permission [String] Permission, in [FULL_CONTROL, WRITE, WRITE_ACP, READ, READ_ACP]
|
|
|
|
# @param acl [String] Permissions, must be in ['private', 'public-read', 'public-read-write', 'authenticated-read']
|
|
|
|
# @param options [Hash]
|
|
|
|
# @option options versionId [String] specify a particular version to retrieve
|
2010-11-22 15:44:44 +08:00
|
|
|
#
|
2013-01-13 19:49:47 -06:00
|
|
|
# @see http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTObjectPUTacl.html
|
2010-11-22 15:44:44 +08: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 15:44:44 +08: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 15:44:44 +08:00
|
|
|
request({
|
|
|
|
:body => data,
|
|
|
|
:expects => 200,
|
2011-08-23 10:24:11 -04:00
|
|
|
:headers => headers,
|
2010-11-22 15:44:44 +08:00
|
|
|
:host => "#{bucket_name}.#{@host}",
|
|
|
|
:method => 'PUT',
|
|
|
|
:path => CGI.escape(object_name),
|
|
|
|
: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 15:44:44 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|