Beispiel #1
0
    def test_put_bucket_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, "?acl")
                self.assertEqual(query.data,
                                 payload.sample_access_control_policy_result)
                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)
        return s3.put_bucket_acl("mybucket", policy).addCallback(check_result)
Beispiel #2
0
 def _parse_acl(self, response):
     """
     Parse an C{AccessControlPolicy} XML document and convert it into an
     L{AccessControlPolicy} instance.
     """
     status, xml_bytes = response
     return AccessControlPolicy.from_xml(xml_bytes)
Beispiel #3
0
 def _parse_acl(self, xml_bytes):
     """
     Parse an C{AccessControlPolicy} XML document and convert it into an
     L{AccessControlPolicy} instance.
     """
     return AccessControlPolicy.from_xml(xml_bytes)
Beispiel #4
0
        data = access_control_policy.to_xml()
        details = self._details(
            method=b"PUT",
            url_context=self._url_context(bucket=bucket, object_name=b"?acl"),
            body=data,
        )
        d = self._submit(self._query_factory(details))
        d.addCallback(self._parse_acl)
        return d

    def _parse_acl(self, (response, xml_bytes)):
        """
        Parse an C{AccessControlPolicy} XML document and convert it into an
        L{AccessControlPolicy} instance.
        """
        return AccessControlPolicy.from_xml(xml_bytes)

    def put_object(self, bucket, object_name, data=None, content_type=None,
                   metadata={}, amz_headers={}, body_producer=None):
        """
        Put an object in a bucket.

        An existing object with the same name will be replaced.

        @param bucket: The name of the bucket.
        @param object: The name of the object.
        @param data: The data to write.
        @param content_type: The type of data being written.
        @param metadata: A C{dict} used to build C{x-amz-meta-*} headers.
        @param amz_headers: A C{dict} used to build C{x-amz-*} headers.
        @return: A C{Deferred} that will fire with the result of request.