fog--fog/lib/fog/aws/requests/s3/put_bucket.rb

69 lines
1.7 KiB
Ruby
Raw Normal View History

unless Fog.mocking?
module Fog
module AWS
class S3
# Create an S3 bucket
#
# ==== Parameters
# * bucket_name<~String> - name of bucket to create
# * options<~Hash> - config arguments for bucket. Defaults to {}.
# * :location_constraint<~Symbol> - sets the location for the bucket
#
# ==== Returns
# * response<~Fog::AWS::Response>:
# * status<~Integer> - 200
def put_bucket(bucket_name, options = {})
if options['LocationConstraint']
data =
<<-DATA
<CreateBucketConfiguration>
<LocationConstraint>#{options['LocationConstraint']}</LocationConstraint>
</CreateBucketConfiguration>
DATA
else
data = nil
end
request({
2009-08-16 18:44:50 +00:00
:expects => 200,
:body => data,
:headers => {},
:host => "#{bucket_name}.#{@host}",
:method => 'PUT'
})
end
end
end
end
else
module Fog
module AWS
class S3
def put_bucket(bucket_name, options = {})
response = Fog::Response.new
response.status = 200
2009-08-09 05:40:42 +00:00
bucket = {
:objects => {},
'Name' => bucket_name,
'CreationDate' => Time.now,
'Payer' => 'BucketOwner'
}
2009-08-09 05:40:42 +00:00
if options['LocationConstraint']
bucket['LocationConstraint'] = options['LocationConstraint']
else
bucket['LocationConstraint'] = ''
end
Fog::AWS::S3.data[:buckets][bucket_name] = bucket
response
end
end
end
end
end