]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
googlestorage_container.py: Use Amazon S3 namespace, since Google insists on using it.
authorDaira Hopwood <daira@jacaranda.org>
Mon, 15 Apr 2013 20:00:35 +0000 (21:00 +0100)
committerDaira Hopwood <daira@jacaranda.org>
Fri, 17 Apr 2015 21:31:39 +0000 (22:31 +0100)
Signed-off-by: Daira Hopwood <david-sarah@jacaranda.org>
src/allmydata/storage/backends/cloud/googlestorage/googlestorage_container.py
src/allmydata/test/test_storage.py

index cf6f1537faa9b8bcd5ab99d94543c612020f0307..4d407ed68abf281906d1dc4a7520218445f8a79c 100644 (file)
@@ -91,7 +91,9 @@ class GoogleStorageContainer(CommonContainerMixin):
 
     USER_AGENT = "Tahoe-LAFS Google Storage client"
     URI = "https://storage.googleapis.com"
-    NAMESPACE = "{http://doc.storage.googleapis.com/2010-04-03}"
+    NAMESPACE = "{http://doc.s3.amazonaws.com/2006-03-01}"
+    # I can't get Google to actually use their own namespace?!
+    #NAMESPACE="{http://doc.storage.googleapis.com/2010-04-03}"
 
     def __init__(self, auth_client, project_id, bucket_name, override_reactor=None):
         CommonContainerMixin.__init__(self, bucket_name, override_reactor)
@@ -169,7 +171,8 @@ class GoogleStorageContainer(CommonContainerMixin):
         last_modified = element.find(self.NAMESPACE + "LastModified").text
         etag = element.find(self.NAMESPACE + "ETag").text
         size = int(element.find(self.NAMESPACE + "Size").text)
-        storage_class = element.find(self.NAMESPACE + "StorageClass").text
+        storage_class = element.find(self.NAMESPACE + "StorageClass")
+        storage_class = "STANDARD"
         owner = None # Don't bother parsing this at the moment
 
         return ContainerItem(key, last_modified, etag, size, storage_class,
@@ -215,6 +218,7 @@ class GoogleStorageContainer(CommonContainerMixin):
             request_headers = {
                 'Authorization': [auth_header],
                 "x-goog-api-version": ["2"],
+                "x-goog-project-id": [self._project_id],
             }
             url = self._make_container_url(self.URI)
             url += "?prefix=" + urllib.quote(prefix, safe='')
@@ -239,3 +243,18 @@ def configure_googlestorage_container(storedir, config):
 
     authclient = AuthenticationClient(account_email, private_key)
     return GoogleStorageContainer(authclient, project_id, bucket_name)
+
+
+if __name__ == '__main__':
+    from twisted.internet import reactor
+    import sys
+    auth = AuthenticationClient(sys.argv[1], file(sys.argv[2]).read())
+    gsc = GoogleStorageContainer(auth, sys.argv[3], sys.argv[4])
+    def println(result):
+        for item in result.contents:
+            print "Bucket has key", item.key
+        reactor.stop()
+    def gotAuth(value):
+        gsc.list_objects().addCallback(println)
+    auth.get_authorization_header().addCallback(gotAuth)
+    reactor.run()
index e7417da6279cd3f4c2ed4d62c3c96fb1bec2fe26..107673fbff0940a3d28908236ca8ea7620f2cea8 100644 (file)
@@ -822,7 +822,7 @@ class GoogleStorageBackend(unittest.TestCase):
         """
         LIST_RESPONSE = """\
 <?xml version='1.0' encoding='utf-8'?>
-<ListBucketResult xmlns='http://doc.storage.googleapis.com/2010-04-03'>
+<ListBucketResult xmlns='http://doc.s3.amazonaws.com/2006-03-01'>
   <Name>thebucket</Name>
   <Prefix>xxx xxx</Prefix>
   <Marker>themark</Marker>
@@ -834,7 +834,6 @@ class GoogleStorageBackend(unittest.TestCase):
     <LastModified>2013-01-27T01:23:45.678Z</LastModified>
     <ETag>"abc"</ETag>
     <Size>123</Size>
-    <StorageClass>STANDARD</StorageClass>
     <Owner>
       <ID>something</ID>
       <DisplayName></DisplayName>
@@ -847,7 +846,6 @@ class GoogleStorageBackend(unittest.TestCase):
     <LastModified>2013-01-28T01:23:45.678Z</LastModified>
     <ETag>"def"</ETag>
     <Size>456</Size>
-    <StorageClass>NOTSTANDARD</StorageClass>
     <Owner>
       <ID>something</ID>
       <DisplayName></DisplayName>
@@ -872,6 +870,7 @@ class GoogleStorageBackend(unittest.TestCase):
             "https://storage.googleapis.com/thebucket?prefix=xxx%20xxx",
             {"Authorization": ["Bearer thetoken"],
              "x-goog-api-version": ["2"],
+             "x-goog-project-id": ["123"],
              },
             body=None,
             need_response_body=True)
@@ -888,13 +887,11 @@ class GoogleStorageBackend(unittest.TestCase):
         self.assertEqual(item1.modification_date, "2013-01-27T01:23:45.678Z")
         self.assertEqual(item1.etag, '"abc"')
         self.assertEqual(item1.size, 123)
-        self.assertEqual(item1.storage_class, 'STANDARD')
         self.assertEqual(item1.owner, None) # meh, who cares
         self.assertEqual(item2.key, "xxx xxx2")
         self.assertEqual(item2.modification_date, "2013-01-28T01:23:45.678Z")
         self.assertEqual(item2.etag, '"def"')
         self.assertEqual(item2.size, 456)
-        self.assertEqual(item2.storage_class, 'NOTSTANDARD')
         self.assertEqual(item2.owner, None) # meh, who cares
 
     def test_put_object(self):