Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Implemented support for adding Google Storage group-by-email grants.
Browse files Browse the repository at this point in the history
  • Loading branch information
mfschwartz committed Jan 26, 2011
1 parent ac7a6d7 commit 0ccfda5
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 5 deletions.
42 changes: 40 additions & 2 deletions boto/gs/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def add_email_grant(self, permission, email_address,
account your are granting the permission to.
:type recursive: boolean
:param recursive: A boolean value to controls whether the command
:param recursive: A boolean value to controls whether the call
will apply the grant to all keys within the bucket
or not. The default value is False. By passing a
True value, the call will iterate through all keys
Expand Down Expand Up @@ -109,7 +109,7 @@ def add_user_grant(self, permission, user_id, recursive=False, headers=None):
the permission to.
:type recursive: bool
:param recursive: A boolean value to controls whether the command
:param recursive: A boolean value to controls whether the call
will apply the grant to all keys within the bucket
or not. The default value is False. By passing a
True value, the call will iterate through all keys
Expand All @@ -127,6 +127,44 @@ def add_user_grant(self, permission, user_id, recursive=False, headers=None):
for key in self:
key.add_user_grant(permission, user_id, headers=headers)

def add_group_email_grant(self, permission, email_address, recursive=False,
headers=None):
"""
Convenience method that provides a quick way to add an email group
grant to a bucket. This method retrieves the current ACL, creates a new
grant based on the parameters passed in, adds that grant to the ACL and
then PUT's the new ACL back to GS.
:type permission: string
:param permission: The permission being granted. Should be one of:
READ|WRITE|FULL_CONTROL
See http://code.google.com/apis/storage/docs/developer-guide.html#authorization
for more details on permissions.
:type email_address: string
:param email_address: The email address associated with the Google
Group to which you are granting the permission.
:type recursive: bool
:param recursive: A boolean value to controls whether the call
will apply the grant to all keys within the bucket
or not. The default value is False. By passing a
True value, the call will iterate through all keys
in the bucket and apply the same grant to each key.
CAUTION: If you have a lot of keys, this could take
a long time!
"""
if permission not in GSPermissions:
raise self.connection.provider.storage_permissions_error(
'Unknown Permission: %s' % permission)
acl = self.get_acl(headers=headers)
acl.add_group_email_grant(permission, email_address)
self.set_acl(acl, headers=headers)
if recursive:
for key in self:
key.add_group_email_grant(permission, email_address,
headers=headers)

# Method with same input signature as boto.s3.bucket.Bucket.list_grants()
# (but returning different object type), to allow polymorphic treatment
# at application layer.
Expand Down
6 changes: 3 additions & 3 deletions boto/gs/key.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def add_user_grant(self, permission, user_id):
acl.add_user_grant(permission, user_id)
self.set_acl(acl)

def add_group_email_grant(self, permission, email_address):
def add_group_email_grant(self, permission, email_address, headers=None):
"""
Convenience method that provides a quick way to add an email group
grant to a key. This method retrieves the current ACL, creates a new
Expand All @@ -82,9 +82,9 @@ def add_group_email_grant(self, permission, email_address):
:param email_address: The email address associated with the Google
Group to which you are granting the permission.
"""
acl = self.get_acl()
acl = self.get_acl(headers=headers)
acl.add_group_email_grant(permission, email_address)
self.set_acl(acl)
self.set_acl(acl, headers=headers)

def add_group_grant(self, permission, group_id):
"""
Expand Down
20 changes: 20 additions & 0 deletions boto/storage_uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,26 @@ def get_acl(self, validate=True, headers=None, version_id=None):
self.check_response(acl, 'acl', self.uri)
return acl

def add_group_email_grant(self, permission, email_address, recursive=False,
validate=True, headers=None):
if self.scheme != 'gs':
raise ValueError('add_group_email_grant() not supported for %s '
'URIs.' % self.scheme)
if self.object_name:
if recursive:
raise ValueError('add_group_email_grant() on key-ful URI cannot '
'specify recursive=True')
key = self.get_key(validate, headers)
self.check_response(key, 'key', self.uri)
key.add_group_email_grant(permission, email_address, headers)
elif self.bucket_name:
bucket = self.get_bucket(validate, headers)
bucket.add_group_email_grant(permission, email_address, recursive,
headers)
else:
raise InvalidUriError('add_group_email_grant() on bucket-less URI %s' %
self.uri)

def add_email_grant(self, permission, email_address, recursive=False,
validate=True, headers=None):
if not self.bucket_name:
Expand Down

0 comments on commit 0ccfda5

Please sign in to comment.