2010-03-13 16:37:24 -05:00
|
|
|
module Fog
|
2011-06-15 17:26:43 -04:00
|
|
|
module Storage
|
|
|
|
class AWS
|
2010-03-13 16:37:24 -05:00
|
|
|
class Real
|
2009-08-07 22:55:11 -04:00
|
|
|
|
|
|
|
# Create an S3 bucket
|
|
|
|
#
|
2013-01-10 23:31:16 -05:00
|
|
|
# @param bucket_name [String] name of bucket to create
|
|
|
|
# @option options [Hash] config arguments for bucket. Defaults to {}.
|
|
|
|
# @option options LocationConstraint [Symbol] sets the location for the bucket
|
|
|
|
# @option options x-amz-acl [String] Permissions, must be in ['private', 'public-read', 'public-read-write', 'authenticated-read']
|
2009-08-07 22:55:11 -04:00
|
|
|
#
|
2013-01-10 23:31:16 -05:00
|
|
|
# @return [Excon::Response] response:
|
|
|
|
# * status [Integer] 200
|
2010-10-29 19:38:17 -04:00
|
|
|
#
|
2013-01-10 23:31:16 -05:00
|
|
|
# @see http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTBucketPUT.html
|
|
|
|
#
|
2009-08-07 22:55:11 -04:00
|
|
|
def put_bucket(bucket_name, options = {})
|
2010-10-29 19:38:17 -04:00
|
|
|
if location_constraint = options.delete('LocationConstraint')
|
2009-08-07 22:55:11 -04:00
|
|
|
data =
|
2010-03-13 16:37:24 -05:00
|
|
|
<<-DATA
|
|
|
|
<CreateBucketConfiguration>
|
2010-10-29 19:38:17 -04:00
|
|
|
<LocationConstraint>#{location_constraint}</LocationConstraint>
|
2010-03-13 16:37:24 -05:00
|
|
|
</CreateBucketConfiguration>
|
|
|
|
DATA
|
2009-08-07 22:55:11 -04:00
|
|
|
else
|
|
|
|
data = nil
|
|
|
|
end
|
|
|
|
request({
|
2009-12-04 00:39:04 -05:00
|
|
|
:expects => 200,
|
|
|
|
:body => data,
|
2010-10-29 19:38:17 -04:00
|
|
|
:headers => options,
|
2009-12-04 00:39:04 -05:00
|
|
|
:idempotent => true,
|
|
|
|
:host => "#{bucket_name}.#{@host}",
|
|
|
|
:method => 'PUT'
|
2009-08-07 22:55:11 -04:00
|
|
|
})
|
2009-07-13 22:14:59 -04:00
|
|
|
end
|
2009-08-07 22:55:11 -04:00
|
|
|
|
2009-07-13 22:14:59 -04:00
|
|
|
end
|
2009-08-07 22:55:11 -04:00
|
|
|
|
2010-10-29 21:16:36 -04:00
|
|
|
class Mock # :nodoc:all
|
2009-08-07 22:55:11 -04:00
|
|
|
|
|
|
|
def put_bucket(bucket_name, options = {})
|
2011-01-21 23:45:37 -05:00
|
|
|
acl = options['x-amz-acl'] || 'private'
|
|
|
|
if !['private', 'public-read', 'public-read-write', 'authenticated-read'].include?(acl)
|
|
|
|
raise Excon::Errors::BadRequest.new('invalid x-amz-acl')
|
|
|
|
else
|
2011-05-19 18:35:33 -04:00
|
|
|
self.data[:acls][:bucket][bucket_name] = self.class.acls(acl)
|
2010-11-18 17:17:11 -05:00
|
|
|
end
|
2011-01-21 23:45:37 -05:00
|
|
|
|
2009-11-20 14:08:08 -05:00
|
|
|
response = Excon::Response.new
|
2009-08-07 22:55:11 -04:00
|
|
|
response.status = 200
|
2009-08-09 01:40:42 -04:00
|
|
|
bucket = {
|
2009-08-16 14:45:52 -04:00
|
|
|
:objects => {},
|
|
|
|
'Name' => bucket_name,
|
|
|
|
'CreationDate' => Time.now,
|
2009-11-21 13:28:18 -05:00
|
|
|
'Owner' => { 'DisplayName' => 'owner', 'ID' => 'some_id'},
|
2009-08-16 14:45:52 -04:00
|
|
|
'Payer' => 'BucketOwner'
|
2009-08-08 15:31:32 -04:00
|
|
|
}
|
2009-08-09 01:40:42 -04:00
|
|
|
if options['LocationConstraint']
|
|
|
|
bucket['LocationConstraint'] = options['LocationConstraint']
|
|
|
|
else
|
2010-10-29 20:22:25 -04:00
|
|
|
bucket['LocationConstraint'] = nil
|
2009-08-09 01:40:42 -04:00
|
|
|
end
|
2011-05-19 18:35:33 -04:00
|
|
|
unless self.data[:buckets][bucket_name]
|
|
|
|
self.data[:buckets][bucket_name] = bucket
|
2009-09-08 14:54:38 -04:00
|
|
|
end
|
2009-08-07 22:55:11 -04:00
|
|
|
response
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2009-07-13 22:14:59 -04:00
|
|
|
end
|
|
|
|
end
|
2010-03-13 16:37:24 -05:00
|
|
|
end
|