From 37a12353c07c2b1064a2af44652a140d17bc9a04 Mon Sep 17 00:00:00 2001 From: Daira Hopwood Date: Mon, 15 Apr 2013 21:00:35 +0100 Subject: [PATCH] googlestorage_container.py: Use Amazon S3 namespace, since Google insists on using it. Signed-off-by: Daira Hopwood --- .../googlestorage/googlestorage_container.py | 23 +++++++++++++++++-- src/allmydata/test/test_storage.py | 7 ++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/allmydata/storage/backends/cloud/googlestorage/googlestorage_container.py b/src/allmydata/storage/backends/cloud/googlestorage/googlestorage_container.py index cf6f1537..4d407ed6 100644 --- a/src/allmydata/storage/backends/cloud/googlestorage/googlestorage_container.py +++ b/src/allmydata/storage/backends/cloud/googlestorage/googlestorage_container.py @@ -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() diff --git a/src/allmydata/test/test_storage.py b/src/allmydata/test/test_storage.py index 726ef93a..d8954788 100644 --- a/src/allmydata/test/test_storage.py +++ b/src/allmydata/test/test_storage.py @@ -829,7 +829,7 @@ class GoogleStorageBackend(unittest.TestCase): """ LIST_RESPONSE = """\ - + thebucket xxx xxx themark @@ -841,7 +841,6 @@ class GoogleStorageBackend(unittest.TestCase): 2013-01-27T01:23:45.678Z "abc" 123 - STANDARD something @@ -854,7 +853,6 @@ class GoogleStorageBackend(unittest.TestCase): 2013-01-28T01:23:45.678Z "def" 456 - NOTSTANDARD something @@ -879,6 +877,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) @@ -895,13 +894,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): -- 2.45.2