2010-03-13 16:37:24 -05:00
|
|
|
module Fog
|
|
|
|
module AWS
|
2010-09-03 04:11:45 -04:00
|
|
|
class S3
|
2010-03-13 16:37:24 -05:00
|
|
|
class Real
|
2009-08-07 22:55:11 -04:00
|
|
|
|
|
|
|
# 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
|
2009-11-02 21:48:49 -05:00
|
|
|
# * response<~Excon::Response>:
|
2009-08-07 22:55:11 -04:00
|
|
|
# * status<~Integer> - 200
|
|
|
|
def put_bucket(bucket_name, options = {})
|
|
|
|
if options['LocationConstraint']
|
|
|
|
data =
|
2010-03-13 16:37:24 -05:00
|
|
|
<<-DATA
|
|
|
|
<CreateBucketConfiguration>
|
|
|
|
<LocationConstraint>#{options['LocationConstraint']}</LocationConstraint>
|
|
|
|
</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,
|
|
|
|
:headers => {},
|
|
|
|
: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-03-13 16:37:24 -05:00
|
|
|
class Mock
|
2009-08-07 22:55:11 -04:00
|
|
|
|
|
|
|
def put_bucket(bucket_name, options = {})
|
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
|
|
|
|
bucket['LocationConstraint'] = ''
|
|
|
|
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
|
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
|