OLD | NEW |
1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
2 # Copyright 2013 Google Inc. All Rights Reserved. | 2 # Copyright 2013 Google Inc. All Rights Reserved. |
3 # | 3 # |
4 # Licensed under the Apache License, Version 2.0 (the "License"); | 4 # Licensed under the Apache License, Version 2.0 (the "License"); |
5 # you may not use this file except in compliance with the License. | 5 # you may not use this file except in compliance with the License. |
6 # You may obtain a copy of the License at | 6 # You may obtain a copy of the License at |
7 # | 7 # |
8 # http://www.apache.org/licenses/LICENSE-2.0 | 8 # http://www.apache.org/licenses/LICENSE-2.0 |
9 # | 9 # |
10 # Unless required by applicable law or agreed to in writing, software | 10 # Unless required by applicable law or agreed to in writing, software |
11 # distributed under the License is distributed on an "AS IS" BASIS, | 11 # distributed under the License is distributed on an "AS IS" BASIS, |
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 # See the License for the specific language governing permissions and | 13 # See the License for the specific language governing permissions and |
14 # limitations under the License. | 14 # limitations under the License. |
15 """Gsutil API for interacting with cloud storage providers.""" | 15 """Gsutil API for interacting with cloud storage providers.""" |
16 | 16 |
17 from __future__ import absolute_import | 17 from __future__ import absolute_import |
18 | 18 |
19 | 19 |
20 class CloudApi(object): | 20 class CloudApi(object): |
21 """Abstract base class for interacting with cloud storage providers. | 21 """Abstract base class for interacting with cloud storage providers. |
22 | 22 |
23 Implementations of the gsutil Cloud API are not guaranteed to be thread-safe. | 23 Implementations of the gsutil Cloud API are not guaranteed to be thread-safe. |
24 Behavior when calling a gsutil Cloud API instance simultaneously across | 24 Behavior when calling a gsutil Cloud API instance simultaneously across |
25 threads is undefined and doing so will likely cause errors. Therefore, | 25 threads is undefined and doing so will likely cause errors. Therefore, |
26 a separate instance of the gsutil Cloud API should be instantiated per-thread. | 26 a separate instance of the gsutil Cloud API should be instantiated per-thread. |
27 """ | 27 """ |
28 | 28 |
29 def __init__(self, bucket_storage_uri_class, logger, provider=None, debug=0): | 29 def __init__(self, bucket_storage_uri_class, logger, provider=None, |
| 30 debug=0, trace_token=None): |
30 """Performs necessary setup for interacting with the cloud storage provider. | 31 """Performs necessary setup for interacting with the cloud storage provider. |
31 | 32 |
32 Args: | 33 Args: |
33 bucket_storage_uri_class: boto storage_uri class, used by APIs that | 34 bucket_storage_uri_class: boto storage_uri class, used by APIs that |
34 provide boto translation or mocking. | 35 provide boto translation or mocking. |
35 logger: logging.logger for outputting log messages. | 36 logger: logging.logger for outputting log messages. |
36 provider: Default provider prefix describing cloud storage provider to | 37 provider: Default provider prefix describing cloud storage provider to |
37 connect to. | 38 connect to. |
38 debug: Debug level for the API implementation (0..3). | 39 debug: Debug level for the API implementation (0..3). |
| 40 trace_token: Google internal trace token to pass to the API |
| 41 implementation (string). |
39 """ | 42 """ |
40 self.bucket_storage_uri_class = bucket_storage_uri_class | 43 self.bucket_storage_uri_class = bucket_storage_uri_class |
41 self.logger = logger | 44 self.logger = logger |
42 self.provider = provider | 45 self.provider = provider |
43 self.debug = debug | 46 self.debug = debug |
| 47 self.trace_token = trace_token |
44 | 48 |
45 def GetBucket(self, bucket_name, provider=None, fields=None): | 49 def GetBucket(self, bucket_name, provider=None, fields=None): |
46 """Gets Bucket metadata. | 50 """Gets Bucket metadata. |
47 | 51 |
48 Args: | 52 Args: |
49 bucket_name: Name of the bucket. | 53 bucket_name: Name of the bucket. |
50 provider: Cloud storage provider to connect to. If not present, | 54 provider: Cloud storage provider to connect to. If not present, |
51 class-wide default is used. | 55 class-wide default is used. |
52 fields: If present, return only these Bucket metadata fields, for | 56 fields: If present, return only these Bucket metadata fields, for |
53 example, ['logging', 'defaultObjectAcl'] | 57 example, ['logging', 'defaultObjectAcl'] |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 object_name: Object name. | 266 object_name: Object name. |
263 download_stream: Stream to send the object data to. | 267 download_stream: Stream to send the object data to. |
264 provider: Cloud storage provider to connect to. If not present, | 268 provider: Cloud storage provider to connect to. If not present, |
265 class-wide default is used. | 269 class-wide default is used. |
266 generation: Generation of the object to retrieve. | 270 generation: Generation of the object to retrieve. |
267 object_size: Total size of the object being downloaded. | 271 object_size: Total size of the object being downloaded. |
268 download_strategy: Cloud API download strategy to use for download. | 272 download_strategy: Cloud API download strategy to use for download. |
269 start_byte: Starting point for download (for resumable downloads and | 273 start_byte: Starting point for download (for resumable downloads and |
270 range requests). Can be set to negative to request a range | 274 range requests). Can be set to negative to request a range |
271 of bytes (python equivalent of [:-3]) | 275 of bytes (python equivalent of [:-3]) |
272 end_byte: Ending point for download (for range requests). | 276 end_byte: Ending byte number, inclusive, for download (for range |
| 277 requests). If None, download the rest of the object. |
273 progress_callback: Optional callback function for progress notifications. | 278 progress_callback: Optional callback function for progress notifications. |
274 Receives calls with arguments | 279 Receives calls with arguments |
275 (bytes_transferred, total_size). | 280 (bytes_transferred, total_size). |
276 serialization_data: Implementation-specific dict containing serialization | 281 serialization_data: Implementation-specific JSON string of a dict |
277 information for the download. | 282 containing serialization information for the download. |
278 digesters: Dict of {string : digester}, where string is a name of a hash | 283 digesters: Dict of {string : digester}, where string is a name of a hash |
279 algorithm, and digester is a validation digester that supports | 284 algorithm, and digester is a validation digester that supports |
280 update(bytes) and digest() using that algorithm. | 285 update(bytes) and digest() using that algorithm. |
281 Implementation can set the digester value to None to indicate | 286 Implementation can set the digester value to None to indicate |
282 bytes were not successfully digested on-the-fly. | 287 bytes were not successfully digested on-the-fly. |
283 | 288 |
284 Raises: | 289 Raises: |
285 ArgumentException for errors during input validation. | 290 ArgumentException for errors during input validation. |
286 ServiceException for errors interacting with cloud storage providers. | 291 ServiceException for errors interacting with cloud storage providers. |
287 | 292 |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 | 600 |
596 | 601 |
597 class PreconditionException(ServiceException): | 602 class PreconditionException(ServiceException): |
598 """Exception raised for precondition failures.""" | 603 """Exception raised for precondition failures.""" |
599 | 604 |
600 | 605 |
601 class NotFoundException(ServiceException): | 606 class NotFoundException(ServiceException): |
602 """Exception raised when a resource is not found (404).""" | 607 """Exception raised when a resource is not found (404).""" |
603 | 608 |
604 | 609 |
| 610 class BucketNotFoundException(NotFoundException): |
| 611 """Exception raised when a bucket resource is not found (404).""" |
| 612 |
| 613 def __init__(self, reason, bucket_name, status=None, body=None): |
| 614 super(BucketNotFoundException, self).__init__(reason, status=status, |
| 615 body=body) |
| 616 self.bucket_name = bucket_name |
| 617 |
| 618 |
605 class NotEmptyException(ServiceException): | 619 class NotEmptyException(ServiceException): |
606 """Exception raised when trying to delete a bucket is not empty.""" | 620 """Exception raised when trying to delete a bucket is not empty.""" |
607 | 621 |
608 | 622 |
609 class BadRequestException(ServiceException): | 623 class BadRequestException(ServiceException): |
610 """Exception raised for malformed requests. | 624 """Exception raised for malformed requests. |
611 | 625 |
612 Where it is possible to detect invalid arguments prior to sending them | 626 Where it is possible to detect invalid arguments prior to sending them |
613 to the server, an ArgumentException should be raised instead. | 627 to the server, an ArgumentException should be raised instead. |
614 """ | 628 """ |
615 | 629 |
616 | 630 |
617 class AccessDeniedException(ServiceException): | 631 class AccessDeniedException(ServiceException): |
618 """Exception raised when authenticated user has insufficient access rights. | 632 """Exception raised when authenticated user has insufficient access rights. |
619 | 633 |
620 This is raised when the authentication process succeeded but the | 634 This is raised when the authentication process succeeded but the |
621 authenticated user does not have access rights to the requested resource. | 635 authenticated user does not have access rights to the requested resource. |
622 """ | 636 """ |
623 | 637 |
624 | 638 |
OLD | NEW |