Arsene Rei has proposed merging 
lp:~dreamhosters/txaws/921347-get-bucket-lifecycle-2 into lp:txaws.

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

For more details, see:
https://code.launchpad.net/~dreamhosters/txaws/921347-get-bucket-lifecycle-2/+merge/90226
-- 
https://code.launchpad.net/~dreamhosters/txaws/921347-get-bucket-lifecycle-2/+merge/90226
Your team txAWS Technical List is requested to review the proposed merge of 
lp:~dreamhosters/txaws/921347-get-bucket-lifecycle-2 into lp:txaws.
=== modified file 'txaws/s3/client.py'
--- txaws/s3/client.py	2012-01-24 23:18:36 +0000
+++ txaws/s3/client.py	2012-01-26 00:47:24 +0000
@@ -20,7 +20,8 @@
 from txaws.client.base import BaseClient, BaseQuery, error_wrapper
 from txaws.s3.acls import AccessControlPolicy
 from txaws.s3.model import (
-    Bucket, BucketItem, BucketListing, ItemOwner, RequestPayment)
+    Bucket, BucketItem, BucketListing, ItemOwner, LifecycleConfiguration,
+    LifecycleConfigurationRule, RequestPayment)
 from txaws.s3.exception import S3Error
 from txaws.service import AWSServiceEndpoint, S3_ENDPOINT
 from txaws.util import XML, calculate_md5
@@ -180,6 +181,35 @@
         root = XML(xml_bytes)
         return root.text or ""
 
+    def get_bucket_lifecycle(self, bucket):
+        """
+        Get the lifecycle configuration of a bucket.
+
+        @param bucket: The name of the bucket.
+        @return: A C{Deferred} that will fire with the bucket's lifecycle
+        configuration.
+        """
+        query = self.query_factory(
+            action='GET', creds=self.creds, endpoint=self.endpoint,
+            bucket=bucket, object_name='?lifecycle')
+        return query.submit().addCallback(self._parse_lifecycle_config)
+
+    def _parse_lifecycle_config(self, xml_bytes):
+        """Parse a C{LifecycleConfiguration} XML document."""
+        root = XML(xml_bytes)
+        contents = []
+        rules = []
+
+        for content_data in root.findall("Rule"):
+            id = content_data.findtext("ID")
+            prefix = content_data.findtext("Prefix")
+            status = content_data.findtext("Status")
+            expiration = content_data.findtext("Expiration/Days")
+            rules.append(
+                LifecycleConfigurationRule(id, prefix, status, expiration))
+
+        return LifecycleConfiguration(rules) 
+
     def get_bucket_acl(self, bucket):
         """
         Get the access control policy for a bucket.

=== modified file 'txaws/s3/model.py'
--- txaws/s3/model.py	2011-03-26 12:32:44 +0000
+++ txaws/s3/model.py	2012-01-26 00:47:24 +0000
@@ -34,6 +34,9 @@
 
 
 class BucketListing(object):
+    """
+    A mapping for the data in a bucket listing.
+    """
     def __init__(self, name, prefix, marker, max_keys, is_truncated,
                  contents=None, common_prefixes=None):
         self.name = name
@@ -45,6 +48,25 @@
         self.common_prefixes = common_prefixes
 
 
+class LifecycleConfiguration(object):
+    """
+    Returns the lifecycle configuration information set on the bucket.
+    """
+    def __init__(self, rules):
+        self.rules = rules
+
+
+class LifecycleConfigurationRule(object):
+    """
+    Container for elements that describe a lifecycle rule.
+    """
+    def __init__(self, id, prefix, status, expiration):
+        self.id = id
+        self.prefix = prefix
+        self.status = status
+        self.expiration = expiration
+
+
 class FileChunk(object):
     """
     An Amazon S3 file chunk.

=== modified file 'txaws/s3/tests/test_client.py'
--- txaws/s3/tests/test_client.py	2012-01-24 23:18:36 +0000
+++ txaws/s3/tests/test_client.py	2012-01-26 00:47:24 +0000
@@ -231,6 +231,40 @@
         d = s3.get_bucket_location("mybucket")
         return d.addCallback(check_results)
 
+    def test_get_bucket_lifecycle(self):
+        """
+        L{S3Client.get_bucket_lifecycle} creates a L{Query} to get a bucket's
+        lifecycle.  It parses the returned C{LifecycleConfiguration} XML
+        document and returns a C{Deferred} that fires with the bucket's region.
+        """
+
+        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, "?lifecycle")
+                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_lifecycle_result)
+
+        def check_results(lifecycle_config):
+            self.assertEquals(lifecycle_config, "")
+
+        creds = AWSCredentials("foo", "bar")
+        s3 = client.S3Client(creds, query_factory=StubQuery)
+        d = s3.get_bucket_lifecycle("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-24 22:52:02 +0000
+++ txaws/testing/payload.py	2012-01-26 00:47:24 +0000
@@ -1007,3 +1007,16 @@
     </Grant>
   </AccessControlList>
 </AccessControlPolicy>"""
+
+sample_s3_get_bucket_lifecycle_result = """\
+<?xml version="1.0" encoding="UTF-8"?>
+<LifecycleConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/";>
+   <Rule>
+      <ID>30-day-log-deletion-rule</ID>
+      <Prefix>logs</Prefix>
+      <Status>Enabled</Status>
+      <Expiration>
+         <Days>30</Days>
+      </Expiration>
+   </Rule>
+</LifecycleConfiguration>"""

_______________________________________________
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