class Twin
Attributes
destination_aws_access_key_id[RW]
these exist for ironworker compatibility. It should probaby be seperated out to a wrapper.
destination_aws_secret_access_key[RW]
these exist for ironworker compatibility. It should probaby be seperated out to a wrapper.
destination_s3_bucket[RW]
these exist for ironworker compatibility. It should probaby be seperated out to a wrapper.
source_aws_access_key_id[RW]
these exist for ironworker compatibility. It should probaby be seperated out to a wrapper.
source_aws_secret_access_key[RW]
these exist for ironworker compatibility. It should probaby be seperated out to a wrapper.
source_s3_bucket[RW]
these exist for ironworker compatibility. It should probaby be seperated out to a wrapper.
Public Class Methods
go(params)
click to toggle source
# File lib/s3twin/twin.rb, line 20 def go(params) puts 'Starting S3Twin run' @source = AWS::S3.new( :access_key_id => params['source_aws_access_key_id'], :secret_access_key => params['source_aws_secret_access_key']) @source_bucket = @source.buckets[params['source_s3_bucket']] @destination = AWS::S3.new( :access_key_id => params['destination_aws_access_key_id'], :secret_access_key => params['destination_aws_secret_access_key']) @destination_bucket = @destination.buckets[params['destination_s3_bucket']] @source_bucket.objects.each do |obj| dest_key = @destination_bucket.objects[obj.key] begin unless dest_key.exists? puts "Creating: #{obj.key}" obj.copy_to(dest_key, :acl => public_acl(obj)) else unless etag_match(obj.key,obj.etag) puts "Updating: #{obj.key}" obj.copy_to(dest_key, :acl => public_acl(obj)) else puts "Skipping: #{obj.key}" end end rescue AWS::S3::Errors::AccessDenied puts "Access Denied: #{obj.key}" end end puts 'Completed S3Twin run' end
Private Class Methods
etag_match(key,etag)
click to toggle source
# File lib/s3twin/twin.rb, line 71 def etag_match(key,etag) etag == @destination_bucket.objects[key].etag end
public_acl(object)
click to toggle source
# File lib/s3twin/twin.rb, line 54 def public_acl(object) object.acl.grants.each do |grant| if grant.grantee.uri == 'http://acs.amazonaws.com/groups/global/AllUsers' case grant.permission.name.to_s when 'read' return 'public_read' when 'read_write' return 'public_read_write' else return 'private' end else return nil end end end
Public Instance Methods
run()
click to toggle source
# File lib/s3twin/twin.rb, line 6 def run params = { 'source_s3_bucket' => source_s3_bucket, 'source_aws_access_key_id' => source_aws_access_key_id, 'source_aws_secret_access_key' => source_aws_secret_access_key, 'destination_s3_bucket' => destination_s3_bucket, 'destination_aws_access_key_id' => destination_aws_access_key_id, 'destination_aws_secret_access_key' => destination_aws_secret_access_key } Twin.go(params) end