← Back to team overview

txaws-dev team mailing list archive

[Merge] lp:~oubiwann/txaws/919433-missing-put-object-acl into lp:txaws

 

Duncan McGreggor has proposed merging lp:~oubiwann/txaws/919433-missing-put-object-acl into lp:txaws.

Requested reviews:
  txAWS Developers (txaws-dev)
Related bugs:
  Bug #919433 in txAWS: "s3 client is missing put object ACL"
  https://bugs.launchpad.net/txaws/+bug/919433

For more details, see:
https://code.launchpad.net/~oubiwann/txaws/919433-missing-put-object-acl/+merge/89520
-- 
https://code.launchpad.net/~oubiwann/txaws/919433-missing-put-object-acl/+merge/89520
Your team txAWS Developers is requested to review the proposed merge of lp:~oubiwann/txaws/919433-missing-put-object-acl into lp:txaws.
=== modified file 'txaws/s3/client.py'
--- txaws/s3/client.py	2012-01-06 00:00:22 +0000
+++ txaws/s3/client.py	2012-01-21 08:07:26 +0000
@@ -283,6 +283,16 @@
             bucket=bucket, object_name=object_name)
         return query.submit()
 
+    def put_object_acl(self, bucket, object_name, access_control_policy):
+        """
+        Set access control policy on an object.
+        """
+        data = access_control_policy.to_xml()
+        query = self.query_factory(
+            action='PUT', creds=self.creds, endpoint=self.endpoint,
+            bucket=bucket, object_name='%s?acl' % object_name, data=data)
+        return query.submit().addCallback(self._parse_acl)
+
     def get_object_acl(self, bucket, object_name):
         """
         Get the access control policy for an object.

=== modified file 'txaws/s3/tests/test_client.py'
--- txaws/s3/tests/test_client.py	2012-01-06 09:51:07 +0000
+++ txaws/s3/tests/test_client.py	2012-01-21 08:07:26 +0000
@@ -523,6 +523,39 @@
         s3 = client.S3Client(creds, query_factory=StubQuery)
         return s3.delete_object("mybucket", "objectname")
 
+    def test_put_object_acl(self):
+
+        class StubQuery(client.Query):
+
+            def __init__(query, action, creds, endpoint, bucket=None,
+                         object_name=None, data=""):
+                super(StubQuery, query).__init__(action=action, creds=creds,
+                                                 bucket=bucket,
+                                                 object_name=object_name,
+                                                 data=data)
+                self.assertEquals(action, "PUT")
+                self.assertEqual(creds.access_key, "foo")
+                self.assertEqual(creds.secret_key, "bar")
+                self.assertEqual(query.bucket, "mybucket")
+                self.assertEqual(query.object_name, "myobject?acl")
+                self.assertEqual(query.data,
+                                 payload.sample_access_control_policy_result)
+                self.assertEqual(query.metadata, {})
+                self.assertEqual(query.metadata, {})
+
+            def submit(query, url_context=None):
+                return succeed(payload.sample_access_control_policy_result)
+
+        def check_result(result):
+            self.assert_(isinstance(result, AccessControlPolicy))
+
+        creds = AWSCredentials("foo", "bar")
+        s3 = client.S3Client(creds, query_factory=StubQuery)
+        policy = AccessControlPolicy.from_xml(
+            payload.sample_access_control_policy_result)
+        deferred = s3.put_object_acl("mybucket", "myobject", policy)
+        return deferred.addCallback(check_result)
+
     def test_get_object_acl(self):
 
         class StubQuery(client.Query):

=== modified file 'txaws/version.py'
--- txaws/version.py	2011-11-29 08:17:54 +0000
+++ txaws/version.py	2012-01-21 08:07:26 +0000
@@ -1,3 +1,3 @@
-txaws = "0.2.2"
+txaws = "0.2.3"
 ec2_api = "2008-12-01"
 s3_api = "2006-03-01"