2009-08-02 19:37:54 -04:00
|
|
|
module Fog
|
|
|
|
module AWS
|
|
|
|
class S3
|
|
|
|
|
|
|
|
def buckets
|
|
|
|
Fog::AWS::S3::Buckets.new(:connection => self)
|
|
|
|
end
|
|
|
|
|
|
|
|
class Buckets < Fog::Collection
|
|
|
|
|
2009-10-30 03:11:50 -04:00
|
|
|
model Fog::AWS::S3::Bucket
|
2009-10-30 02:35:28 -04:00
|
|
|
|
2009-08-02 19:37:54 -04:00
|
|
|
def all
|
|
|
|
data = connection.get_service.body
|
2009-08-04 13:51:54 -04:00
|
|
|
owner = Fog::AWS::S3::Owner.new(data.delete('Owner').merge!(:connection => connection))
|
2009-09-04 21:24:11 -04:00
|
|
|
buckets = Fog::AWS::S3::Buckets.new(:connection => connection)
|
2009-08-02 19:37:54 -04:00
|
|
|
data['Buckets'].each do |bucket|
|
2009-09-04 21:24:11 -04:00
|
|
|
buckets << Fog::AWS::S3::Bucket.new({
|
2009-10-23 12:42:51 -04:00
|
|
|
:collection => buckets,
|
2009-08-28 12:03:19 -04:00
|
|
|
:connection => connection,
|
|
|
|
:owner => owner
|
2009-08-04 13:51:54 -04:00
|
|
|
}.merge!(bucket))
|
2009-08-02 19:37:54 -04:00
|
|
|
end
|
2009-09-04 21:24:11 -04:00
|
|
|
buckets
|
2009-08-02 19:37:54 -04:00
|
|
|
end
|
|
|
|
|
2009-08-29 14:20:54 -04:00
|
|
|
def get(name, options = {})
|
2009-09-02 00:41:52 -04:00
|
|
|
remap_attributes(options, {
|
2009-09-21 14:40:16 -04:00
|
|
|
:max_keys => 'max-keys',
|
2009-09-02 00:41:52 -04:00
|
|
|
})
|
|
|
|
data = connection.get_bucket(name, options).body
|
|
|
|
bucket = Fog::AWS::S3::Bucket.new({
|
2009-10-23 12:42:51 -04:00
|
|
|
:collection => self,
|
2009-09-02 00:41:52 -04:00
|
|
|
:connection => connection,
|
|
|
|
:name => data['Name']
|
|
|
|
})
|
2009-09-21 14:40:16 -04:00
|
|
|
options = {}
|
2009-09-02 00:41:52 -04:00
|
|
|
for key, value in data
|
2009-09-21 14:40:16 -04:00
|
|
|
if ['Delimiter', 'IsTruncated', 'Marker', 'MaxKeys', 'Prefix'].include?(key)
|
|
|
|
options[key] = value
|
2009-09-01 01:40:07 -04:00
|
|
|
end
|
2009-08-29 14:20:54 -04:00
|
|
|
end
|
2009-10-06 22:16:12 -04:00
|
|
|
bucket.objects.merge_attributes(options)
|
2009-09-02 00:41:52 -04:00
|
|
|
data['Contents'].each do |object|
|
|
|
|
owner = Fog::AWS::S3::Owner.new(object.delete('Owner').merge!(:connection => connection))
|
2009-09-04 21:24:11 -04:00
|
|
|
bucket.objects << Fog::AWS::S3::Object.new({
|
2009-09-02 00:41:52 -04:00
|
|
|
:bucket => bucket,
|
|
|
|
:connection => connection,
|
2009-10-23 12:42:51 -04:00
|
|
|
:collection => bucket.objects,
|
2009-09-02 00:41:52 -04:00
|
|
|
:owner => owner
|
|
|
|
}.merge!(object))
|
|
|
|
end
|
|
|
|
bucket
|
|
|
|
rescue Fog::Errors::NotFound
|
|
|
|
nil
|
2009-08-29 14:20:54 -04:00
|
|
|
end
|
|
|
|
|
2009-08-02 19:37:54 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|