From: Daira Hopwood Date: Mon, 15 Apr 2013 20:00:35 +0000 (+0100) Subject: googlestorage_container.py: Use Amazon S3 namespace, since Google insists on using it. X-Git-Url: https://git.rkrishnan.org/Site/Content/Exhibitors/provisioning?a=commitdiff_plain;h=cd7ad244fc437f70fc393df700654f66c3b913cb;p=tahoe-lafs%2Ftahoe-lafs.git googlestorage_container.py: Use Amazon S3 namespace, since Google insists on using it. Signed-off-by: Daira Hopwood --- 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 e7417da6..107673fb 100644 --- a/src/allmydata/test/test_storage.py +++ b/src/allmydata/test/test_storage.py @@ -822,7 +822,7 @@ class GoogleStorageBackend(unittest.TestCase): """ LIST_RESPONSE = """\ - + thebucket xxx xxx themark @@ -834,7 +834,6 @@ class GoogleStorageBackend(unittest.TestCase): 2013-01-27T01:23:45.678Z "abc" 123 - STANDARD something @@ -847,7 +846,6 @@ class GoogleStorageBackend(unittest.TestCase): 2013-01-28T01:23:45.678Z "def" 456 - NOTSTANDARD something @@ -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):