From: Itamar Turner-Trauring Date: Mon, 4 Mar 2013 19:56:17 +0000 (-0500) Subject: googlestorage_container.py: Implement GET object. X-Git-Url: https://git.rkrishnan.org/components/com_hotproperty/flags/(%5B%5E?a=commitdiff_plain;h=e8cbfe7e0c50dc5590e1f7a84a1b7cc14541b9b8;p=tahoe-lafs%2Ftahoe-lafs.git googlestorage_container.py: Implement GET object. --- diff --git a/src/allmydata/storage/backends/cloud/googlestorage/googlestorage_container.py b/src/allmydata/storage/backends/cloud/googlestorage/googlestorage_container.py index e928464c..5e91c87f 100644 --- a/src/allmydata/storage/backends/cloud/googlestorage/googlestorage_container.py +++ b/src/allmydata/storage/backends/cloud/googlestorage/googlestorage_container.py @@ -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__': diff --git a/src/allmydata/test/test_storage.py b/src/allmydata/test/test_storage.py index 91ec5ae4..d1053034 100644 --- a/src/allmydata/test/test_storage.py +++ b/src/allmydata/test/test_storage.py @@ -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):