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)
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,
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='')
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()
"""
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>
<LastModified>2013-01-27T01:23:45.678Z</LastModified>
<ETag>"abc"</ETag>
<Size>123</Size>
- <StorageClass>STANDARD</StorageClass>
<Owner>
<ID>something</ID>
<DisplayName></DisplayName>
<LastModified>2013-01-28T01:23:45.678Z</LastModified>
<ETag>"def"</ETag>
<Size>456</Size>
- <StorageClass>NOTSTANDARD</StorageClass>
<Owner>
<ID>something</ID>
<DisplayName></DisplayName>
"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)
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):