2010-05-09 21:50:10 -04:00
|
|
|
module Fog
|
2011-06-15 17:26:43 -04:00
|
|
|
module Storage
|
|
|
|
class AWS
|
2010-05-09 21:50:10 -04:00
|
|
|
class Real
|
|
|
|
|
2011-11-14 04:41:40 -05:00
|
|
|
require 'fog/aws/requests/storage/acl_utils'
|
|
|
|
|
2010-05-09 21:50:10 -04:00
|
|
|
# Change access control list for an S3 bucket
|
2013-01-10 23:31:16 -05:00
|
|
|
#
|
|
|
|
# @param bucket_name [String] name of bucket to modify
|
|
|
|
# @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-05-09 21:50:10 -04:00
|
|
|
# or
|
2013-01-10 23:31:16 -05:00
|
|
|
# * EmailAddress [String] Email address of grantee
|
2010-05-09 21:50:10 -04:00
|
|
|
# or
|
2013-01-10 23:31:16 -05:00
|
|
|
# * URI [String] URI of group to grant access for
|
|
|
|
# * Permission [String] Permission, in [FULL_CONTROL, WRITE, WRITE_ACP, READ, READ_ACP]
|
|
|
|
# * acl [String] Permissions, must be in ['private', 'public-read', 'public-read-write', 'authenticated-read']
|
2010-10-29 21:05:59 -04:00
|
|
|
#
|
2013-01-10 23:31:16 -05:00
|
|
|
# @see http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTBucketPUTacl.html
|
2010-10-29 21:05:59 -04:00
|
|
|
|
2010-05-09 21:50:10 -04:00
|
|
|
def put_bucket_acl(bucket_name, acl)
|
2011-08-23 10:29:51 -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:29:51 -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
|
|
|
|
|
|
|
|
headers['Content-MD5'] = Base64.encode64(Digest::MD5.digest(data)).strip
|
|
|
|
headers['Content-Type'] = 'application/json'
|
|
|
|
headers['Date'] = Fog::Time.now.to_date_header
|
2010-05-09 21:50:10 -04:00
|
|
|
|
|
|
|
request({
|
|
|
|
:body => data,
|
|
|
|
:expects => 200,
|
2011-08-23 10:29:51 -04:00
|
|
|
:headers => headers,
|
2013-04-12 06:31:10 -04:00
|
|
|
:bucket_name => bucket_name,
|
2010-05-09 21:50:10 -04:00
|
|
|
:method => 'PUT',
|
2010-06-05 17:19:39 -04:00
|
|
|
:query => {'acl' => nil}
|
2010-05-09 21:50:10 -04:00
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
2011-08-24 21:19:55 -04:00
|
|
|
|
|
|
|
class Mock
|
|
|
|
def put_bucket_acl(bucket_name, acl)
|
|
|
|
if acl.is_a?(Hash)
|
|
|
|
self.data[:acls][:bucket][bucket_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][:bucket][bucket_name] = acl
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-05-09 21:50:10 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|