diff options
author | Lars Otten <ottenl@google.com> | 2013-02-25 17:15:19 -0800 |
---|---|---|
committer | Lars Otten <ottenl@google.com> | 2013-02-28 10:59:44 -0800 |
commit | ef0bc6fe6d68ed3f20319d9e735c13320666eaba (patch) | |
tree | a6b7c79b4d21bec9973f6f1e4bd2bb15de51f1b2 | |
parent | 11052752d5dff94c68a1e328b6676c7cdda5da67 (diff) | |
download | boto-ef0bc6fe6d68ed3f20319d9e735c13320666eaba.tar.gz |
Adds get_logging_config to GS bucket and storage_uri and performs
some related cleanup.
-rw-r--r-- | boto/gs/bucket.py | 60 | ||||
-rwxr-xr-x | boto/storage_uri.py | 10 | ||||
-rw-r--r-- | tests/integration/s3/mock_storage_service.py | 7 |
3 files changed, 71 insertions, 6 deletions
diff --git a/boto/gs/bucket.py b/boto/gs/bucket.py index 2b61f822..a3111d2c 100644 --- a/boto/gs/bucket.py +++ b/boto/gs/bucket.py @@ -737,6 +737,56 @@ class Bucket(S3Bucket): self.set_subresource('logging', xml_str, headers=headers) + def get_logging_config_with_xml(self, headers=None): + """Returns the current status of logging configuration on the bucket as + unparsed XML. + + :param dict headers: Additional headers to send with the request. + + :rtype: 2-Tuple + :returns: 2-tuple containing: + + 1) A dictionary containing the parsed XML response from GCS. The + overall structure is: + + * Logging + + * LogObjectPrefix: Prefix that is prepended to log objects. + * LogBucket: Target bucket for log objects. + + 2) Unparsed XML describing the bucket's logging configuration. + """ + response = self.connection.make_request('GET', self.name, + query_args='logging', + headers=headers) + body = response.read() + boto.log.debug(body) + + if response.status != 200: + raise self.connection.provider.storage_response_error( + response.status, response.reason, body) + + e = boto.jsonresponse.Element() + h = boto.jsonresponse.XmlHandler(e, None) + h.parse(body) + return e, body + + def get_logging_config(self, headers=None): + """Returns the current status of logging configuration on the bucket. + + :param dict headers: Additional headers to send with the request. + + :rtype: dict + :returns: A dictionary containing the parsed XML response from GCS. The + overall structure is: + + * Logging + + * LogObjectPrefix: Prefix that is prepended to log objects. + * LogBucket: Target bucket for log objects. + """ + return self.get_logging_config_with_xml(headers)[0] + def configure_website(self, main_page_suffix=None, error_key=None, headers=None): """Configure this bucket to act as a website @@ -783,8 +833,8 @@ class Bucket(S3Bucket): :param dict headers: Additional headers to send with the request. :rtype: dict - :returns: A dictionary containing a Python representation - of the XML response from GCS. The overall structure is: + :returns: A dictionary containing the parsed XML response from GCS. The + overall structure is: * WebsiteConfiguration @@ -793,7 +843,7 @@ class Bucket(S3Bucket): * NotFoundPage: name of an object to serve when site visitors encounter a 404. """ - return self.get_website_configuration_xml(self, headers)[0] + return self.get_website_configuration_with_xml(headers)[0] def get_website_configuration_with_xml(self, headers=None): """Returns the current status of website configuration on the bucket as @@ -804,8 +854,8 @@ class Bucket(S3Bucket): :rtype: 2-Tuple :returns: 2-tuple containing: - 1) A dictionary containing a Python representation of the XML - response from GCS. The overall structure is: + 1) A dictionary containing the parsed XML response from GCS. The + overall structure is: * WebsiteConfiguration diff --git a/boto/storage_uri.py b/boto/storage_uri.py index 1fd18fb1..31f4c893 100755 --- a/boto/storage_uri.py +++ b/boto/storage_uri.py @@ -704,8 +704,14 @@ class BucketStorageUri(StorageUri): bucket = self.get_bucket(validate, headers) bucket.disable_logging(headers=headers) + def get_logging_config(self, validate=False, headers=None, version_id=None): + self._check_bucket_uri('get_logging_config') + bucket = self.get_bucket(validate, headers) + return bucket.get_logging_config(headers=headers) + def set_website_config(self, main_page_suffix=None, error_key=None, validate=False, headers=None): + self._check_bucket_uri('set_website_config') bucket = self.get_bucket(validate, headers) if not (main_page_suffix or error_key): bucket.delete_website_configuration(headers) @@ -713,10 +719,12 @@ class BucketStorageUri(StorageUri): bucket.configure_website(main_page_suffix, error_key, headers) def get_website_config(self, validate=False, headers=None): + self._check_bucket_uri('get_website_config') bucket = self.get_bucket(validate, headers) - return bucket.get_website_configuration_with_xml(headers) + return bucket.get_website_configuration(headers) def get_versioning_config(self, headers=None): + self._check_bucket_uri('get_versioning_config') bucket = self.get_bucket(False, headers) return bucket.get_versioning_status(headers) diff --git a/tests/integration/s3/mock_storage_service.py b/tests/integration/s3/mock_storage_service.py index a388590e..4b95e505 100644 --- a/tests/integration/s3/mock_storage_service.py +++ b/tests/integration/s3/mock_storage_service.py @@ -250,6 +250,9 @@ class MockBucket(object): def enable_logging(self, target_bucket_prefix): self.logging = True + def get_logging_config(self): + return {"Logging": {}} + def get_acl(self, key_name='', headers=NOT_IMPL, version_id=NOT_IMPL): if key_name: # Return ACL for the key. @@ -471,6 +474,10 @@ class MockBucketStorageUri(object): headers=NOT_IMPL, version_id=NOT_IMPL): self.get_bucket().enable_logging(target_bucket) + def get_logging_config(self, validate=NOT_IMPL, headers=NOT_IMPL, + version_id=NOT_IMPL): + return self.get_bucket().get_logging_config() + def equals(self, uri): return self.uri == uri.uri |