Skip to content

Commit

Permalink
* s3cmd, S3/ACL.py, S3/Config.py: Support for --acl-grant
Browse files Browse the repository at this point in the history
  and --acl-revoke (contributed by Timothee Linden)



git-svn-id: https://s3tools.svn.sourceforge.net/svnroot/s3tools/s3cmd/trunk@407 830e0280-6d2a-0410-9c65-932aecc39d9d
  • Loading branch information
mludvig committed May 20, 2010
1 parent 46631fc commit 99b416b
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
5 changes: 5 additions & 0 deletions ChangeLog
@@ -1,3 +1,8 @@
2010-05-20 Michal Ludvig <mludvig@logix.net.nz>

* s3cmd, S3/ACL.py, S3/Config.py: Support for --acl-grant
and --acl-revoke (contributed by Timothee Linden)

2010-05-20 Michal Ludvig <mludvig@logix.net.nz>

* S3/Exceptions.py, S3/S3.py: Some HTTP_400 exceptions
Expand Down
1 change: 1 addition & 0 deletions NEWS
@@ -1,6 +1,7 @@
s3cmd 0.9.9.92 - ???
==============
* Added [accesslog] command. (needs manpage!)
* Added --acl-grant and --acl-revoke (by Timothee Linden).

s3cmd 0.9.9.91 - 2009-10-08
==============
Expand Down
50 changes: 50 additions & 0 deletions S3/ACL.py
Expand Up @@ -129,6 +129,56 @@ def revokeAnonRead(self):
def appendGrantee(self, grantee):
self.grantees.append(grantee)

def hasGrant(self, name, permission):
name = name.lower()
permission = permission.upper()

for grantee in self.grantees:
if grantee.name.lower() == name:
if grantee.permission == "FULL_CONTROL":
return True
elif grantee.permission.upper() == permission:
return True

return False;

def grant(self, name, permission):
if self.hasGrant(name, permission):
return

name = name.lower()
permission = permission.upper()

if "ALL" == permission:
permission = "FULL_CONTROL"

if "FULL_CONTROL" == permission:
self.revoke(name, "ALL")

grantee = Grantee()
grantee.name = name
grantee.permission = permission

if name.find('@') <= -1: # ultra lame attempt to differenciate emails id from canonical ids
grantee.xsi_type = "CanonicalUser"
grantee.tag = "ID"
else:
grantee.xsi_type = "AmazonCustomerByEmail"
grantee.tag = "EmailAddress"

self.appendGrantee(grantee)


def revoke(self, name, permission):
name = name.lower()
permission = permission.upper()

if "ALL" == permission:
self.grantees = [g for g in self.grantees if not g.name.lower() == name]
else:
self.grantees = [g for g in self.grantees if not (g.name.lower() == name and g.permission.upper() == permission)]


def __str__(self):
tree = getTreeFromXml(ACL.EMPTY_ACL)
tree.attrib['xmlns'] = "http://s3.amazonaws.com/doc/2006-03-01/"
Expand Down
4 changes: 3 additions & 1 deletion S3/Config.py
Expand Up @@ -33,7 +33,9 @@ class Config(object):
get_continue = False
skip_existing = False
recursive = False
acl_public = False
acl_public = None
acl_grants = []
acl_revokes = []
proxy_host = ""
proxy_port = 3128
encrypt = False
Expand Down

0 comments on commit 99b416b

Please sign in to comment.