]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
googlestorage_container.py: Implement GET object.
authorItamar Turner-Trauring <itamar@futurefoundries.com>
Mon, 4 Mar 2013 19:56:17 +0000 (14:56 -0500)
committerDaira Hopwood <daira@jacaranda.org>
Fri, 17 Apr 2015 21:31:38 +0000 (22:31 +0100)
src/allmydata/storage/backends/cloud/googlestorage/googlestorage_container.py
src/allmydata/test/test_storage.py

index e928464c2f433fc5db2e7e7d3b12339940e6c7a8..5e91c87f0ec1f7f4210a4b2657565db7e1cf21b8 100644 (file)
@@ -4,20 +4,19 @@ This requires the oauth2client library:
 http://code.google.com/p/google-api-python-client/downloads/list
 """
 
+# Maybe we can make a thing that looks like httplib2.Http but actually uses
+# Twisted?
 import httplib2
 
-from twisted.internet.defer import DeferredLock, maybeDeferred
+from twisted.internet.defer import DeferredLock
 from twisted.internet.threads import deferToThread
 
 from oauth2client.client import SignedJwtAssertionCredentials
 
 from zope.interface import implements
 
-from allmydata.util import log
-from allmydata.node import InvalidValueError
 from allmydata.storage.backends.cloud.cloud_common import IContainer, \
-     CloudServiceError, ContainerItem, ContainerListing, ContainerRetryMixin, \
-     HTTPClientMixin
+     CloudServiceError, ContainerItem, ContainerListing, CommonContainerMixin
 
 
 def configure_googlestorage_container(*args):
@@ -81,13 +80,34 @@ class AuthenticationClient(object):
         return d
 
 
-class GoogleStorageContainer(HTTPClientMixin, ContainerRetryMixin):
+class GoogleStorageContainer(CommonContainerMixin):
     implements(IContainer)
 
     USER_AGENT = "Tahoe-LAFS Google Storage client"
+    URI = "https://storage.googleapis.com"
 
     def __init__(self, auth_client, project_id, bucket_name, override_reactor=None):
-        pass
+        CommonContainerMixin.__init__(self, bucket_name, override_reactor)
+        self._auth_client = auth_client
+        self._project_id = project_id # Only need for bucket creation/deletion
+
+    def _get_object(self, object_name):
+        """
+        Get an object from this container.
+        """
+        d = self._auth_client.get_authorization_header()
+        def _do_get(auth_header):
+            request_headers = {
+                'Authorization': [auth_header],
+                "x-goog-api-version": ["2"],
+            }
+            url = self._make_object_url(self.URI, object_name)
+            return self._http_request("GET object", 'GET', url, request_headers,
+                                      body=None,
+                                      need_response_body=True)
+        d.addCallback(_do_get)
+        d.addCallback(lambda (response, body): body)
+        return d
 
 
 if __name__ == '__main__':
index 91ec5ae48731781d25f27d81dffb9682924e88ae..d10530346f7c047f80700db373348e3996c92d6d 100644 (file)
@@ -767,7 +767,7 @@ class GoogleStorageBackend(unittest.TestCase):
     unless noted otherwise.
     """
     class Response(object):
-        def __init__(self, code, headers):
+        def __init__(self, code, headers={}):
             self.code = code
             self.headers = headers
 
@@ -775,7 +775,7 @@ class GoogleStorageBackend(unittest.TestCase):
         self.reactor = Clock()
         class FakeAuthenticationClient(object):
             def get_authorization_header(self):
-                return "Bearer thetoken"
+                return defer.succeed("Bearer thetoken")
         self.auth = FakeAuthenticationClient()
         self.container = googlestorage_container.GoogleStorageContainer(
             self.auth, "123", "thebucket", self.reactor)
@@ -787,7 +787,7 @@ class GoogleStorageBackend(unittest.TestCase):
         """
         d = defer.Deferred()
         self.container._http_request = mock.create_autospec(
-            self._container._http_request, return_value=d)
+            self.container._http_request, return_value=d)
         return d
 
     def test_create(self):