module Cumulus::S3
Public Class Methods
Public: Provide a mapping of S3
buckets to their names. Lazily loads resources.
Returns the buckets mapped to their names
# File lib/s3/S3.rb, line 62 def buckets @buckets ||= init_buckets end
# File lib/s3/S3.rb, line 8 def client(region = nil) @clients ||= {} if !region then region = "us-east-1" end @clients[region] ||= Aws::S3::Client.new(Configuration.instance.client.merge({:force_path_style => true, :region => region})) end
Public: Get the full data for a bucket. Lazily loads resources only once.
bucket_name - the name of the bucket to get
Returns the full bucket
# File lib/s3/S3.rb, line 51 def full_bucket(bucket_name) @monkey_patched ||= monkey_patch_bucket @full_buckets ||= Hash.new bucket = buckets[bucket_name] @full_buckets[bucket_name] ||= Aws::S3::Bucket.new(name: bucket_name, client: client(bucket.location)) end
Public: Static method that will get an S3
bucket from AWS by its name
name - the name of the bucket to get
Returns the Aws::S3::Types::Bucket by that name
# File lib/s3/S3.rb, line 39 def get_aws(name) buckets.fetch(name) rescue KeyError puts "No S3 bucket named #{name}" exit end
Public: Refereshes the bucket list and full_buckets map
# File lib/s3/S3.rb, line 67 def refresh! @buckets = init_buckets @full_buckets = Hash.new end
Public: A mapping of region name to its hosted zone id. This mapping is needed because the S3
API doesn't expose the hosted ids, you have to get them at docs.aws.amazon.com/general/latest/gr/rande.html#s3_region.
# File lib/s3/S3.rb, line 30 def zone_ids @@zone_ids end
Private Class Methods
Internal: Load the buckets and map them to their names.
Returns the buckets mapped to their names
# File lib/s3/S3.rb, line 84 def init_buckets Hash[client.list_buckets.buckets.map { |bucket| [bucket.name, bucket] }] end
Internal: Monkey patch Bucket so it can get its location
# File lib/s3/S3.rb, line 75 def monkey_patch_bucket require "aws_extensions/s3/Bucket" Aws::S3::Types::Bucket.send(:include, AwsExtensions::S3::Types::Bucket) true end