Arsene Rei has proposed merging 
lp:~dreamhosters/txaws/921349-get-bucket-logging-method into lp:txaws.

Requested reviews:
  txAWS Technical List (txaws-tech)
Related bugs:
  Bug #921349 in txAWS: "S3: Add GET Bucket logging method"
  https://bugs.launchpad.net/txaws/+bug/921349

For more details, see:
https://code.launchpad.net/~dreamhosters/txaws/921349-get-bucket-logging-method/+merge/90540

Add GET Bucket logging functionality.
-- 
https://code.launchpad.net/~dreamhosters/txaws/921349-get-bucket-logging-method/+merge/90540
Your team txAWS Technical List is requested to review the proposed merge of 
lp:~dreamhosters/txaws/921349-get-bucket-logging-method into lp:txaws.
=== modified file 'txaws/s3/client.py'
--- txaws/s3/client.py	2012-01-27 19:54:27 +0000
+++ txaws/s3/client.py	2012-01-27 21:52:28 +0000
@@ -22,8 +22,8 @@
 from txaws.s3.acls import AccessControlPolicy
 from txaws.s3.model import (
     Bucket, BucketItem, BucketListing, ItemOwner, LifecycleConfiguration,
-    LifecycleConfigurationRule, NotificationConfiguration, RequestPayment,
-    WebsiteConfiguration)
+    LifecycleConfigurationRule, LoggingStatus, NotificationConfiguration,
+    RequestPayment, WebsiteConfiguration)
 from txaws.s3.exception import S3Error
 from txaws.service import AWSServiceEndpoint, S3_ENDPOINT
 from txaws.util import XML, calculate_md5
@@ -253,6 +253,25 @@
 
         return NotificationConfiguration(topic, event)
 
+    def get_bucket_logging_status(self, bucket):
+        """
+        Get the logging status of a bucket.
+
+        @param bucket: The name of the bucket.  @return: A C{Deferred} that
+        will request the bucket's logging status.
+        """
+        query = self.query_factory(
+            action='GET', creds=self.creds, endpoint=self.endpoint,
+            bucket=bucket, object_name='?logging')
+        return query.submit().addCallback(self._parse_logging_status)
+
+    def _parse_logging_status(self, xml_bytes):
+        """Parse a C{VersioningConfiguration} XML document."""
+        root = XML(xml_bytes)
+        status = root.findtext("Status")
+
+        return LoggingStatus(status)
+
     def get_bucket_acl(self, bucket):
         """
         Get the access control policy for a bucket.

=== modified file 'txaws/s3/model.py'
--- txaws/s3/model.py	2012-01-27 19:47:22 +0000
+++ txaws/s3/model.py	2012-01-27 21:52:28 +0000
@@ -90,6 +90,14 @@
         self.event = event
 
 
+class LoggingStatus(object):
+    """
+    Container for the bucket logging status.
+    """
+    def __init__(self, status=None):
+        self.status = status
+
+
 class FileChunk(object):
     """
     An Amazon S3 file chunk.

=== modified file 'txaws/s3/tests/test_client.py'
--- txaws/s3/tests/test_client.py	2012-01-27 20:44:11 +0000
+++ txaws/s3/tests/test_client.py	2012-01-27 21:52:28 +0000
@@ -462,6 +462,113 @@
         d = s3.get_bucket_notification_config("mybucket")
         return d.addCallback(check_results)
 
+    def test_get_bucket_logging_status(self):
+        """
+        L{S3Client.get_bucket_logging_status} creates a L{Query} to get a
+        bucket's logging status.  It parses the returned C{LoggingStatus} XML
+        document and returns a C{Deferred} that requests the bucket's logging
+        status.
+        """
+
+        class StubQuery(client.Query):
+
+            def __init__(query, action, creds, endpoint, bucket=None,
+                         object_name=None):
+                super(StubQuery, query).__init__(action=action, creds=creds,
+                                                 bucket=bucket,
+                                                 object_name=object_name)
+                self.assertEquals(action, "GET")
+                self.assertEqual(creds.access_key, "foo")
+                self.assertEqual(creds.secret_key, "bar")
+                self.assertEqual(query.bucket, "mybucket")
+                self.assertEqual(query.object_name, "?logging")
+                self.assertEqual(query.data, "")
+                self.assertEqual(query.metadata, {})
+                self.assertEqual(query.amz_headers, {})
+
+            def submit(query, url_context=None):
+                return succeed(payload.sample_s3_get_bucket_logging_result)
+
+        def check_results(logging_status):
+            self.assertEquals(logging_status.status, None)
+
+        creds = AWSCredentials("foo", "bar")
+        s3 = client.S3Client(creds, query_factory=StubQuery)
+        d = s3.get_bucket_logging_status("mybucket")
+        return d.addCallback(check_results)
+
+    def test_get_bucket_logging_status_enabled(self):
+        """
+        L{S3Client.get_bucket_logging_status} creates a L{Query} to get a
+        bucket's logging status.  It parses the returned C{LoggingStatus} XML
+        document and returns a C{Deferred} that requests the bucket's logging
+        status which is enabled.
+        """
+
+        class StubQuery(client.Query):
+
+            def __init__(query, action, creds, endpoint, bucket=None,
+                         object_name=None):
+                super(StubQuery, query).__init__(action=action, creds=creds,
+                                                 bucket=bucket,
+                                                 object_name=object_name)
+                self.assertEquals(action, "GET")
+                self.assertEqual(creds.access_key, "foo")
+                self.assertEqual(creds.secret_key, "bar")
+                self.assertEqual(query.bucket, "mybucket")
+                self.assertEqual(query.object_name, "?logging")
+                self.assertEqual(query.data, "")
+                self.assertEqual(query.metadata, {})
+                self.assertEqual(query.amz_headers, {})
+
+            def submit(query, url_context=None):
+                return succeed(payload.
+                               sample_s3_get_bucket_logging_enabled_result)
+
+        def check_results(logging_status):
+            self.assertEquals(logging_status.status, 'Enabled')
+
+        creds = AWSCredentials("foo", "bar")
+        s3 = client.S3Client(creds, query_factory=StubQuery)
+        d = s3.get_bucket_logging_status("mybucket")
+        return d.addCallback(check_results)
+
+    def test_get_bucket_logging_status_suspended(self):
+        """
+        L{S3Client.get_bucket_logging_status} creates a L{Query} to get a
+        bucket's logging status.  It parses the returned C{LoggingStatus} XML
+        document and returns a C{Deferred} that requests the bucket's logging
+        status which is suspended.
+        """
+
+        class StubQuery(client.Query):
+
+            def __init__(query, action, creds, endpoint, bucket=None,
+                         object_name=None):
+                super(StubQuery, query).__init__(action=action, creds=creds,
+                                                 bucket=bucket,
+                                                 object_name=object_name)
+                self.assertEquals(action, "GET")
+                self.assertEqual(creds.access_key, "foo")
+                self.assertEqual(creds.secret_key, "bar")
+                self.assertEqual(query.bucket, "mybucket")
+                self.assertEqual(query.object_name, "?logging")
+                self.assertEqual(query.data, "")
+                self.assertEqual(query.metadata, {})
+                self.assertEqual(query.amz_headers, {})
+
+            def submit(query, url_context=None):
+                return succeed(payload.
+                               sample_s3_get_bucket_logging_suspended_result)
+
+        def check_results(logging_status):
+            self.assertEquals(logging_status.status, 'Suspended')
+
+        creds = AWSCredentials("foo", "bar")
+        s3 = client.S3Client(creds, query_factory=StubQuery)
+        d = s3.get_bucket_logging_status("mybucket")
+        return d.addCallback(check_results)
+
     def test_delete_bucket(self):
 
         class StubQuery(client.Query):

=== modified file 'txaws/testing/payload.py'
--- txaws/testing/payload.py	2012-01-27 20:08:20 +0000
+++ txaws/testing/payload.py	2012-01-27 21:52:28 +0000
@@ -1071,3 +1071,16 @@
        <Event>s3:ReducedRedundancyLostObject</Event>
    </TopicConfiguration>
 </NotificationConfiguration>"""
+
+sample_s3_get_bucket_logging_result = """\
+<VersioningConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"/>"""
+
+sample_s3_get_bucket_logging_enabled_result = """\
+<VersioningConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/";>
+  <Status>Enabled</Status>
+</VersioningConfiguration>"""
+
+sample_s3_get_bucket_logging_suspended_result = """\
+<VersioningConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/";>
+  <Status>Suspended</Status>
+</VersioningConfiguration>"""

_______________________________________________
Mailing list: https://launchpad.net/~txaws-dev
Post to     : txaws-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~txaws-dev
More help   : https://help.launchpad.net/ListHelp

Reply via email to