Created
March 12, 2012 12:38
-
-
Save lstoll/2021554 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
WORKER_THREADS = 10 | |
require "bundler" | |
Bundler.require | |
unless ARGV.size == 3 | |
puts "USAGE: cmd <s3 key> <s3 secret> <bucket name>" | |
exit | |
end | |
marker = "" | |
AWS::S3::Base.establish_connection!( | |
:access_key_id => ARGV[0], | |
:secret_access_key => ARGV[1] | |
) | |
bucket = ARGV[2] | |
threads = [] | |
queue = Queue.new | |
# Consumer | |
threads << Thread.new do | |
loop do | |
objects = Bucket.objects(bucket_name, :marker=>marker, :max_keys=>1000) | |
break if objects.size == 0 | |
marker = objects.last.key | |
objects.each do |obj| | |
queue << obj.key | |
# puts "#{obj.key}" | |
end | |
end | |
end | |
# worker | |
(1..WORKER_THREADS).each do |i| | |
threads << Thread.new do | |
item = queue.pop | |
puts "Updating permissions for obj: " + item | |
policy = S3Object.acl(item, bucket) | |
policy.grants << ACL::Grant.grant(:public_read) | |
S3Object.acl(item, bucket, policy) | |
# SET PERMS | |
end | |
end | |
threads.each {|t| t.join} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source :rubygems | |
gem "aws-s3", :require => 'aws/s3' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment