2009-08-02 19:37:54 -04:00
|
|
|
module Fog
|
|
|
|
module AWS
|
|
|
|
class S3
|
|
|
|
|
|
|
|
class Bucket < Fog::Model
|
|
|
|
|
2009-08-30 17:43:01 -04:00
|
|
|
attribute :creation_date, 'CreationDate'
|
|
|
|
attribute :location
|
|
|
|
attribute :name, 'Name'
|
|
|
|
attribute :owner
|
2009-08-04 13:51:54 -04:00
|
|
|
|
|
|
|
def initialize(attributes = {})
|
|
|
|
super
|
|
|
|
end
|
2009-08-04 01:50:52 -04:00
|
|
|
|
2009-08-29 14:20:54 -04:00
|
|
|
def buckets
|
|
|
|
@buckets
|
|
|
|
end
|
|
|
|
|
2009-08-30 17:14:11 -04:00
|
|
|
def destroy
|
2009-08-04 01:50:52 -04:00
|
|
|
connection.delete_bucket(name)
|
2009-08-30 17:14:11 -04:00
|
|
|
buckets.delete(name)
|
2009-08-27 23:47:01 -04:00
|
|
|
true
|
2009-09-01 01:40:07 -04:00
|
|
|
rescue Fog::Errors::NotFound
|
|
|
|
false
|
2009-08-04 01:50:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def location
|
2009-08-30 17:14:11 -04:00
|
|
|
@location ||= begin
|
|
|
|
data = s3.get_bucket_location(name)
|
|
|
|
data.body['LocationConstraint']
|
|
|
|
end
|
2009-08-04 01:50:52 -04:00
|
|
|
end
|
|
|
|
|
2009-08-13 01:48:17 -04:00
|
|
|
def objects
|
2009-08-17 20:06:25 -04:00
|
|
|
Fog::AWS::S3::Objects.new(
|
|
|
|
:bucket => self,
|
|
|
|
:connection => connection
|
|
|
|
)
|
2009-08-13 01:48:17 -04:00
|
|
|
end
|
|
|
|
|
2009-08-04 01:50:52 -04:00
|
|
|
def payer
|
2009-08-30 17:14:11 -04:00
|
|
|
@payer ||= begin
|
|
|
|
data = connection.get_request_payment(name)
|
|
|
|
data.body['Payer']
|
|
|
|
end
|
2009-08-04 01:50:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def payer=(new_payer)
|
|
|
|
connection.put_request_payment(name, new_payer)
|
2009-08-04 01:54:34 -04:00
|
|
|
@payer = new_payer
|
2009-08-04 01:50:52 -04:00
|
|
|
end
|
|
|
|
|
2009-08-30 17:14:11 -04:00
|
|
|
def reload
|
|
|
|
buckets.get(name)
|
|
|
|
end
|
|
|
|
|
2009-08-04 01:50:52 -04:00
|
|
|
def save
|
|
|
|
options = {}
|
|
|
|
if @location
|
|
|
|
options['LocationConstraint'] = @location
|
|
|
|
end
|
|
|
|
connection.put_bucket(name, options)
|
2009-08-29 14:20:54 -04:00
|
|
|
buckets[name] = self
|
2009-08-27 23:47:01 -04:00
|
|
|
true
|
2009-08-04 01:50:52 -04:00
|
|
|
end
|
2009-08-02 19:37:54 -04:00
|
|
|
|
2009-08-28 12:03:19 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def buckets=(new_buckets)
|
|
|
|
@buckets = new_buckets
|
|
|
|
end
|
|
|
|
|
2009-08-02 19:37:54 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|