OLD | NEW |
1 # Copyright 2010 Google Inc. | 1 # Copyright 2010 Google Inc. |
2 # | 2 # |
3 # Permission is hereby granted, free of charge, to any person obtaining a | 3 # Permission is hereby granted, free of charge, to any person obtaining a |
4 # copy of this software and associated documentation files (the | 4 # copy of this software and associated documentation files (the |
5 # "Software"), to deal in the Software without restriction, including | 5 # "Software"), to deal in the Software without restriction, including |
6 # without limitation the rights to use, copy, modify, merge, publish, dis- | 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 | 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- | 8 # persons to whom the Software is furnished to do so, subject to the fol- |
9 # lowing conditions: | 9 # lowing conditions: |
10 # | 10 # |
11 # The above copyright notice and this permission notice shall be included | 11 # The above copyright notice and this permission notice shall be included |
12 # in all copies or substantial portions of the Software. | 12 # in all copies or substantial portions of the Software. |
13 # | 13 # |
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | 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- | 15 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- |
16 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT | 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, | 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, | 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 | 19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
20 # IN THE SOFTWARE. | 20 # IN THE SOFTWARE. |
21 | 21 |
22 import boto | 22 import boto |
23 from boto import handler | 23 from boto import handler |
24 from boto.exception import InvalidAclError | 24 from boto.exception import InvalidAclError |
25 from boto.gs.acl import ACL | 25 from boto.gs.acl import ACL, CannedACLStrings |
26 from boto.gs.acl import SupportedPermissions as GSPermissions | 26 from boto.gs.acl import SupportedPermissions as GSPermissions |
27 from boto.gs.key import Key as GSKey | 27 from boto.gs.key import Key as GSKey |
28 from boto.s3.acl import Policy | 28 from boto.s3.acl import Policy |
29 from boto.s3.bucket import Bucket as S3Bucket | 29 from boto.s3.bucket import Bucket as S3Bucket |
30 import xml.sax | 30 import xml.sax |
31 | 31 |
32 class Bucket(S3Bucket): | 32 class Bucket(S3Bucket): |
33 | 33 |
34 def __init__(self, connection=None, name=None, key_class=GSKey): | 34 def __init__(self, connection=None, name=None, key_class=GSKey): |
35 super(Bucket, self).__init__(connection, name, key_class) | 35 super(Bucket, self).__init__(connection, name, key_class) |
(...skipping 12 matching lines...) Expand all Loading... |
48 body = response.read() | 48 body = response.read() |
49 if response.status == 200: | 49 if response.status == 200: |
50 acl = ACL(self) | 50 acl = ACL(self) |
51 h = handler.XmlHandler(acl, self) | 51 h = handler.XmlHandler(acl, self) |
52 xml.sax.parseString(body, h) | 52 xml.sax.parseString(body, h) |
53 return acl | 53 return acl |
54 else: | 54 else: |
55 raise self.connection.provider.storage_response_error( | 55 raise self.connection.provider.storage_response_error( |
56 response.status, response.reason, body) | 56 response.status, response.reason, body) |
57 | 57 |
| 58 def set_canned_acl(self, acl_str, key_name='', headers=None, |
| 59 version_id=None): |
| 60 assert acl_str in CannedACLStrings |
| 61 |
| 62 if headers: |
| 63 headers[self.connection.provider.acl_header] = acl_str |
| 64 else: |
| 65 headers={self.connection.provider.acl_header: acl_str} |
| 66 |
| 67 query_args='acl' |
| 68 if version_id: |
| 69 query_args += '&versionId=%s' % version_id |
| 70 response = self.connection.make_request('PUT', self.name, key_name, |
| 71 headers=headers, query_args=query_args) |
| 72 body = response.read() |
| 73 if response.status != 200: |
| 74 raise self.connection.provider.storage_response_error( |
| 75 response.status, response.reason, body) |
| 76 |
58 # Method with same signature as boto.s3.bucket.Bucket.add_email_grant(), | 77 # Method with same signature as boto.s3.bucket.Bucket.add_email_grant(), |
59 # to allow polymorphic treatment at application layer. | 78 # to allow polymorphic treatment at application layer. |
60 def add_email_grant(self, permission, email_address, | 79 def add_email_grant(self, permission, email_address, |
61 recursive=False, headers=None): | 80 recursive=False, headers=None): |
62 """ | 81 """ |
63 Convenience method that provides a quick way to add an email grant | 82 Convenience method that provides a quick way to add an email grant |
64 to a bucket. This method retrieves the current ACL, creates a new | 83 to a bucket. This method retrieves the current ACL, creates a new |
65 grant based on the parameters passed in, adds that grant to the ACL | 84 grant based on the parameters passed in, adds that grant to the ACL |
66 and then PUT's the new ACL back to GS. | 85 and then PUT's the new ACL back to GS. |
67 | 86 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 for key in self: | 183 for key in self: |
165 key.add_group_email_grant(permission, email_address, | 184 key.add_group_email_grant(permission, email_address, |
166 headers=headers) | 185 headers=headers) |
167 | 186 |
168 # Method with same input signature as boto.s3.bucket.Bucket.list_grants() | 187 # Method with same input signature as boto.s3.bucket.Bucket.list_grants() |
169 # (but returning different object type), to allow polymorphic treatment | 188 # (but returning different object type), to allow polymorphic treatment |
170 # at application layer. | 189 # at application layer. |
171 def list_grants(self, headers=None): | 190 def list_grants(self, headers=None): |
172 acl = self.get_acl(headers=headers) | 191 acl = self.get_acl(headers=headers) |
173 return acl.entries | 192 return acl.entries |
| 193 |
| 194 def disable_logging(self, headers=None): |
| 195 xml_str = '<?xml version="1.0" encoding="UTF-8"?><Logging/>' |
| 196 self.set_subresource('logging', xml_str, headers=headers) |
| 197 |
| 198 def enable_logging(self, target_bucket, target_prefix=None, headers=None, |
| 199 canned_acl=None): |
| 200 if isinstance(target_bucket, Bucket): |
| 201 target_bucket = target_bucket.name |
| 202 xml_str = '<?xml version="1.0" encoding="UTF-8"?><Logging>' |
| 203 xml_str = (xml_str + '<LogBucket>%s</LogBucket>' % target_bucket) |
| 204 if target_prefix: |
| 205 xml_str = (xml_str + |
| 206 '<LogObjectPrefix>%s</LogObjectPrefix>' % target_prefix) |
| 207 if canned_acl: |
| 208 xml_str = (xml_str + |
| 209 '<PredefinedAcl>%s</PredefinedAcl>' % canned_acl) |
| 210 xml_str = xml_str + '</Logging>' |
| 211 |
| 212 self.set_subresource('logging', xml_str, headers=headers) |
OLD | NEW |