def startElement(self, name, attrs, connection): if name == 'AccessControlPolicy': self.namespace = attrs.get('xmlns', None) return None if name == 'Owner': self.owner = User(self) return self.owner elif name == 'AccessControlList': self.acl = ACL(self) return self.acl else: return None
def test_set_bucket_acl(self): bucket = conn.get_bucket(test_bucket) p = Policy() acl = ACL() grant = Grant(id='test1', display_name='test1', type='CanonicalUser', permission='READ') acl.add_grant(grant) p.owner = User(id='1234567890', display_name='test') p.acl = acl bucket.set_acl(acl_or_str=p, headers={'content-type': 'text/plain'})
class Policy(object): def __init__(self, parent=None): self.parent = parent self.namespace = None self.acl = None def __repr__(self): grants = [] for g in self.acl.grants: if g.id == self.owner.id: grants.append("%s (owner) = %s" % (g.display_name, g.permission)) else: if g.type == 'CanonicalUser': u = g.display_name elif g.type == 'Group': u = g.uri else: u = g.email_address grants.append("%s = %s" % (u, g.permission)) return "<Policy: %s>" % ", ".join(grants) def startElement(self, name, attrs, connection): if name == 'AccessControlPolicy': self.namespace = attrs.get('xmlns', None) return None if name == 'Owner': self.owner = User(self) return self.owner elif name == 'AccessControlList': self.acl = ACL(self) return self.acl else: return None def endElement(self, name, value, connection): if name == 'Owner': pass elif name == 'AccessControlList': pass else: setattr(self, name, value) def to_xml(self): if self.namespace is not None: s = '<AccessControlPolicy xmlns="{0}">'.format(self.namespace) else: s = '<AccessControlPolicy>' s += self.owner.to_xml() s += self.acl.to_xml() s += '</AccessControlPolicy>' return s
def startElement(self, name, attrs, connection): for t in self.markers: if name == t[0]: obj = t[1](connection) self.append(obj) return obj if name == 'Owner': # Makes owner available for get_service and # perhaps other lists where not handled by # another element. self.owner = User() return self.owner return None
def test_set_acl(self): owner = User(id='1234567890', display_name='test') acl = ACL() grant = Grant() grant.permission = "READ" grant.display_name = "test" grant.email_address = "*****@*****.**" acl.add_grant(grant) policy = Policy() policy.owner = owner policy.acl = acl bucket = conn.get_bucket(test_bucket) #ret = bucket.set_acl("public-read-write", test_key) ret = bucket.set_acl(policy, test_key) print(ret)
def test_set_acl(self): owner = User(id='1234567890', display_name='test') acl = ACL() grant = Grant() grant.permission = "READ" grant.display_name = "test" grant.email_address = "*****@*****.**" grant.type = 'CanonicalUser' acl.add_grant(grant) policy = Policy() policy.owner = owner policy.acl = acl bucket = conn.get_bucket(test_bucket) # ret = bucket.set_acl("public-read-write", test_key) ret = bucket.set_xml_acl(policy.to_xml(), test_key, headers={'content-type': 'text/plain'}) print(ret)
def startElement(self, name, attrs, connection): if name == 'Owner': self.owner = User(self) return self.owner else: return None
def test_set_bucket_acl(self): bucket = conn.get_bucket(test_bucket) p = Policy() p.acl = ACL() p.owner = User(id='1234567890', display_name='test') bucket.set_acl(policy)