1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/aws/requests/storage/put_bucket.rb

71 lines
2.1 KiB
Ruby
Raw Normal View History

2010-03-13 16:37:24 -05:00
module Fog
module AWS
2010-09-08 17:40:02 -04:00
class Storage
2010-03-13 16:37:24 -05:00
class Real
# Create an S3 bucket
#
# ==== Parameters
# * bucket_name<~String> - name of bucket to create
# * options<~Hash> - config arguments for bucket. Defaults to {}.
# * 'LocationConstraint'<~Symbol> - sets the location for the bucket
# * 'x-amz-acl'<~String> - Permissions, must be in ['private', 'public-read', 'public-read-write', 'authenticated-read']
#
# ==== Returns
# * response<~Excon::Response>:
# * status<~Integer> - 200
#
# ==== See Also
# http://docs.amazonwebservices.com/AmazonS3/latest/API/RESTBucketPUT.html
def put_bucket(bucket_name, options = {})
if location_constraint = options.delete('LocationConstraint')
data =
2010-03-13 16:37:24 -05:00
<<-DATA
<CreateBucketConfiguration>
<LocationConstraint>#{location_constraint}</LocationConstraint>
2010-03-13 16:37:24 -05:00
</CreateBucketConfiguration>
DATA
else
data = nil
end
request({
:expects => 200,
:body => data,
:headers => options,
:idempotent => true,
:host => "#{bucket_name}.#{@host}",
:method => 'PUT'
})
end
end
class Mock # :nodoc:all
def put_bucket(bucket_name, options = {})
2009-11-20 14:08:08 -05:00
response = Excon::Response.new
response.status = 200
2009-08-09 01:40:42 -04:00
bucket = {
:objects => {},
'Name' => bucket_name,
'CreationDate' => Time.now,
2009-11-21 13:28:18 -05:00
'Owner' => { 'DisplayName' => 'owner', 'ID' => 'some_id'},
'Payer' => 'BucketOwner'
}
2009-08-09 01:40:42 -04:00
if options['LocationConstraint']
bucket['LocationConstraint'] = options['LocationConstraint']
else
bucket['LocationConstraint'] = nil
2009-08-09 01:40:42 -04:00
end
2010-03-13 16:37:24 -05:00
unless @data[:buckets][bucket_name]
@data[:buckets][bucket_name] = bucket
2009-09-08 14:54:38 -04:00
end
response
end
end
end
end
2010-03-13 16:37:24 -05:00
end