# File lib/boxgrinder-build/helpers/s3-helper.rb, line 60 def self.endpoints ENDPOINTS end
AWS::S3 object should be instantiated already, as config can be inserted via global AWS.config or via AWS::S3.initialize
# File lib/boxgrinder-build/helpers/s3-helper.rb, line 26 def initialize(ec2, s3, options={}) raise ArgumentError, "ec2 argument must not be nil" if ec2.nil? raise ArgumentError, "s3 argument must not be nil" if s3.nil? @ec2 = ec2 @s3 = s3 @log = options[:log] || LogHelper.new end
# File lib/boxgrinder-build/helpers/s3-helper.rb, line 34 def bucket(options={}) defaults = {:bucket => nil, :acl => :private, :location_constraint => 'us-east-1', :create_if_missing => false} options = parse_opts(options, defaults) s3b = @s3.buckets[options[:bucket]] return s3b if s3b.exists? return @s3.buckets.create(options[:bucket], :acl => options[:acl], :location_constraint => options[:location_constraint]) if options[:create_if_missing] nil end
# File lib/boxgrinder-build/helpers/s3-helper.rb, line 46 def delete_folder(bucket, path) bucket.objects.with_prefix(deslash(path)).map(&:delete) end
# File lib/boxgrinder-build/helpers/s3-helper.rb, line 54 def parse_path(path) return '' if path == '/' #Remove preceding and trailing slashes deslash(path) << '/' end
# File lib/boxgrinder-build/helpers/s3-helper.rb, line 50 def stub_s3obj(bucket, path) bucket.objects[path] end
Remove extraneous slashes on paths to ensure they are valid for S3
# File lib/boxgrinder-build/helpers/s3-helper.rb, line 67 def deslash(path) "#{path.gsub(/^(\/)*/, '').gsub(/(\/)*$/, '')}" end