1
# Copyright (c) 2006,2007 Mitch Garnaat http://garnaat.org/
3
# Permission is hereby granted, free of charge, to any person obtaining a
4
# copy of this software and associated documentation files (the
5
# "Software"), to deal in the Software without restriction, including
6
# without limitation the rights to use, copy, modify, merge, publish, dis-
7
# tribute, sublicense, and/or sell copies of the Software, and to permit
8
# persons to whom the Software is furnished to do so, subject to the fol-
11
# The above copyright notice and this permission notice shall be included
12
# in all copies or substantial portions of the Software.
14
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
16
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
17
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22
from boto.s3.user import User
25
CannedACLStrings = ['private', 'public-read',
26
'public-read-write', 'authenticated-read']
31
def __init__(self, parent=None):
37
for g in self.acl.grants:
38
if g.id == self.owner.id:
39
grants.append("%s (owner) = %s" % (g.display_name, g.permission))
41
if g.type == 'CanonicalUser':
43
elif g.type == 'Group':
47
grants.append("%s = %s" % (u, g.permission))
48
return "<Policy: %s>" % ", ".join(grants)
50
def startElement(self, name, attrs, connection):
52
self.owner = User(self)
54
elif name == 'AccessControlList':
60
def endElement(self, name, value, connection):
63
elif name == 'AccessControlList':
66
setattr(self, name, value)
69
s = '<AccessControlPolicy>'
70
s += self.owner.to_xml()
71
s += self.acl.to_xml()
72
s += '</AccessControlPolicy>'
77
def __init__(self, policy=None):
81
def add_grant(self, grant):
82
self.grants.append(grant)
84
def add_email_grant(self, permission, email_address):
85
grant = Grant(permission=permission, type='AmazonCustomerByEmail',
86
email_address=email_address)
87
self.grants.append(grant)
89
def add_user_grant(self, permission, user_id):
90
grant = Grant(permission=permission, type='CanonicalUser', id=user_id)
91
self.grants.append(grant)
93
def startElement(self, name, attrs, connection):
95
self.grants.append(Grant(self))
96
return self.grants[-1]
100
def endElement(self, name, value, connection):
104
setattr(self, name, value)
107
s = '<AccessControlList>'
108
for grant in self.grants:
110
s += '</AccessControlList>'
115
NameSpace = 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'
117
def __init__(self, permission=None, type=None, id=None,
118
display_name=None, uri=None, email_address=None):
119
self.permission = permission
121
self.display_name = display_name
123
self.email_address = email_address
126
def startElement(self, name, attrs, connection):
127
if name == 'Grantee':
128
self.type = attrs['xsi:type']
131
def endElement(self, name, value, connection):
134
elif name == 'DisplayName':
135
self.display_name = value
138
elif name == 'EmailAddress':
139
self.email_address = value
140
elif name == 'Grantee':
142
elif name == 'Permission':
143
self.permission = value
145
setattr(self, name, value)
149
s += '<Grantee %s xsi:type="%s">' % (self.NameSpace, self.type)
150
if self.type == 'CanonicalUser':
151
s += '<ID>%s</ID>' % self.id
152
s += '<DisplayName>%s</DisplayName>' % self.display_name
153
elif self.type == 'Group':
154
s += '<URI>%s</URI>' % self.uri
156
s += '<EmailAddress>%s</EmailAddress>' % self.email_address
158
s += '<Permission>%s</Permission>' % self.permission