Last active
August 29, 2015 14:18
-
-
Save amalgjose/e4a9cbfda9a5a51c7a2b to your computer and use it in GitHub Desktop.
This code is for changing the permission of all the files in an amazon S3 bucket. This program will add read permissions to all the files present in the specified S3 bucket.
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
class ChangeBucketPermissions(object): | |
##Initializer | |
def __init__(self): | |
self.aws_access_key = "XXXXXXXX" | |
self.aws_secret_key = "XXXXXXXX" | |
aws_region = 'us-east-1' | |
self.s3_conn = boto.connect_s3(aws_access_key_id=self.aws_access_key, | |
aws_secret_access_key=self.aws_secret_key, | |
calling_format=boto.s3.connection.OrdinaryCallingFormat())) | |
self.all_users = 'http://acs.amazonaws.com/groups/global/AllUsers' | |
##This method changes the permission of all files in a bucket | |
def add_read_permissions(self, bucket_name): | |
try: | |
bucket = self.s3_conn.get_bucket(bucket_name) | |
for key in bucket: | |
readable = False | |
acl = key.get_acl() | |
for grant in acl.acl.grants: | |
if grant.permission == 'READ': | |
if grant.uri == self.all_users: | |
readable = True | |
if not readable: | |
key.make_public() | |
except Exception, e: | |
print "Exception occurred while changing all permissions : " + str(e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment