mirror of https://github.com/perkeep/perkeep.git
fixed app engine blobserver urls; added curl client examples
This commit is contained in:
parent
7e3feff72b
commit
f73d1d5c9b
|
@ -1 +1,2 @@
|
||||||
*~
|
*~
|
||||||
|
*.pyc
|
||||||
|
|
|
@ -28,37 +28,35 @@ To test:
|
||||||
# Put -- 200 response
|
# Put -- 200 response
|
||||||
curl -v -L \
|
curl -v -L \
|
||||||
-F file=@./test_data.txt \
|
-F file=@./test_data.txt \
|
||||||
-F 'blob_ref=sha1-126249fd8c18cbb5312a5705746a2af87fba9538' \
|
http://localhost:8080/put/sha1-126249fd8c18cbb5312a5705746a2af87fba9538
|
||||||
http://localhost:8080/put
|
|
||||||
|
|
||||||
# Put with bad blob_ref parameter -- 400 response
|
# Put with bad blob_ref parameter -- 400 response
|
||||||
curl -v -L \
|
curl -v -L \
|
||||||
-F file=@./test_data.txt \
|
-F file=@./test_data.txt \
|
||||||
-F 'blob_ref=sha1-22a7fdd575f4c3e7caa3a55cc83db8b8a6714f0f' \
|
http://localhost:8080/put/sha1-22a7fdd575f4c3e7caa3a55cc83db8b8a6714f0f
|
||||||
http://localhost:8080/put
|
|
||||||
|
|
||||||
# Get present -- the blob
|
# Get present -- the blob
|
||||||
curl -v http://localhost:8080/get?\
|
curl -v http://localhost:8080/get/\
|
||||||
blob_ref=sha1-126249fd8c18cbb5312a5705746a2af87fba9538
|
sha1-126249fd8c18cbb5312a5705746a2af87fba9538
|
||||||
|
|
||||||
# Get missing -- 404
|
# Get missing -- 404
|
||||||
curl -v http://localhost:8080/get?\
|
curl -v http://localhost:8080/get/\
|
||||||
blob_ref=sha1-22a7fdd575f4c3e7caa3a55cc83db8b8a6714f0f
|
sha1-22a7fdd575f4c3e7caa3a55cc83db8b8a6714f0f
|
||||||
|
|
||||||
# Check present -- 200 with blob ref list response
|
# Check present -- 200 with blob ref list response
|
||||||
curl -v http://localhost:8080/check?\
|
curl -v http://localhost:8080/check/\
|
||||||
blob_ref=sha1-126249fd8c18cbb5312a5705746a2af87fba9538
|
sha1-126249fd8c18cbb5312a5705746a2af87fba9538
|
||||||
|
|
||||||
# Check missing -- 404 with empty list response
|
# Check missing -- 404 with empty list response
|
||||||
curl -v http://localhost:8080/check?\
|
curl -v http://localhost:8080/check/\
|
||||||
blob_ref=sha1-22a7fdd575f4c3e7caa3a55cc83db8b8a6714f0f
|
sha1-22a7fdd575f4c3e7caa3a55cc83db8b8a6714f0f
|
||||||
|
|
||||||
# List -- 200 with list of blobs (just one)
|
# List -- 200 with list of blobs (just one)
|
||||||
curl -v http://localhost:8080/list
|
curl -v http://localhost:8080/list
|
||||||
|
|
||||||
# List offset -- 200 with list of no blobs
|
# List offset -- 200 with list of no blobs
|
||||||
curl -v http://localhost:8080/list?\
|
curl -v http://localhost:8080/list/\
|
||||||
after_blob_ref=sha1-126249fd8c18cbb5312a5705746a2af87fba9538
|
sha1-126249fd8c18cbb5312a5705746a2af87fba9538
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -122,8 +120,7 @@ def render_blob_refs(blob_ref_list):
|
||||||
class ListHandler(webapp.RequestHandler):
|
class ListHandler(webapp.RequestHandler):
|
||||||
"""Return chunks that the server has."""
|
"""Return chunks that the server has."""
|
||||||
|
|
||||||
def get(self):
|
def get(self, after_blob_ref):
|
||||||
after_blob_ref = self.request.get('after_blob_ref')
|
|
||||||
count = max(1, min(1000, int(self.request.get('count') or 1000)))
|
count = max(1, min(1000, int(self.request.get('count') or 1000)))
|
||||||
query = Blob.all().order('__key__')
|
query = Blob.all().order('__key__')
|
||||||
if after_blob_ref:
|
if after_blob_ref:
|
||||||
|
@ -136,8 +133,7 @@ class ListHandler(webapp.RequestHandler):
|
||||||
class GetHandler(blobstore_handlers.BlobstoreDownloadHandler):
|
class GetHandler(blobstore_handlers.BlobstoreDownloadHandler):
|
||||||
"""Gets a blob with the given ref."""
|
"""Gets a blob with the given ref."""
|
||||||
|
|
||||||
def get(self):
|
def get(self, blob_ref):
|
||||||
blob_ref = self.request.get('blob_ref')
|
|
||||||
blob = Blob.get_by_key_name(blob_ref)
|
blob = Blob.get_by_key_name(blob_ref)
|
||||||
if not blob:
|
if not blob:
|
||||||
self.error(404)
|
self.error(404)
|
||||||
|
@ -148,8 +144,7 @@ class GetHandler(blobstore_handlers.BlobstoreDownloadHandler):
|
||||||
class CheckHandler(webapp.RequestHandler):
|
class CheckHandler(webapp.RequestHandler):
|
||||||
"""Checks if a Blob is present on this server."""
|
"""Checks if a Blob is present on this server."""
|
||||||
|
|
||||||
def get(self):
|
def get(self, blob_ref):
|
||||||
blob_ref = self.request.get('blob_ref')
|
|
||||||
blob = Blob.get_by_key_name(blob_ref)
|
blob = Blob.get_by_key_name(blob_ref)
|
||||||
if not blob:
|
if not blob:
|
||||||
blob_refs = []
|
blob_refs = []
|
||||||
|
@ -165,9 +160,9 @@ class CheckHandler(webapp.RequestHandler):
|
||||||
class GetUploadUrlHandler(webapp.RequestHandler):
|
class GetUploadUrlHandler(webapp.RequestHandler):
|
||||||
"""Handler to return a URL for a script to get an upload URL."""
|
"""Handler to return a URL for a script to get an upload URL."""
|
||||||
|
|
||||||
def post(self):
|
def post(self, blob_ref):
|
||||||
self.response.headers['Location'] = blobstore.create_upload_url(
|
self.response.headers['Location'] = blobstore.create_upload_url(
|
||||||
'/upload_complete')
|
'/upload_complete/%s' % blob_ref)
|
||||||
self.response.set_status(307)
|
self.response.set_status(307)
|
||||||
|
|
||||||
|
|
||||||
|
@ -196,7 +191,7 @@ class UploadHandler(blobstore_handlers.BlobstoreUploadHandler):
|
||||||
|
|
||||||
return '%s-%s' % (hash_func, hasher.hexdigest())
|
return '%s-%s' % (hash_func, hasher.hexdigest())
|
||||||
|
|
||||||
def store_blob(self, upload_files, error_messages):
|
def store_blob(self, blob_ref, upload_files, error_messages):
|
||||||
"""Store blob information.
|
"""Store blob information.
|
||||||
|
|
||||||
Writes a Blob to the datastore for the uploaded file.
|
Writes a Blob to the datastore for the uploaded file.
|
||||||
|
@ -211,11 +206,6 @@ class UploadHandler(blobstore_handlers.BlobstoreUploadHandler):
|
||||||
if len(upload_files) != 1:
|
if len(upload_files) != 1:
|
||||||
error_messages.append('More than one file.')
|
error_messages.append('More than one file.')
|
||||||
|
|
||||||
blob_ref = self.request.get('blob_ref').lower()
|
|
||||||
if not blob_ref:
|
|
||||||
error_messages.append('Missing "blob_ref" parameter.')
|
|
||||||
return
|
|
||||||
|
|
||||||
if not blob_ref.startswith('sha1-'):
|
if not blob_ref.startswith('sha1-'):
|
||||||
error_messages.append('Only sha1 supported for now.')
|
error_messages.append('Only sha1 supported for now.')
|
||||||
return
|
return
|
||||||
|
@ -239,13 +229,13 @@ class UploadHandler(blobstore_handlers.BlobstoreUploadHandler):
|
||||||
blob.put()
|
blob.put()
|
||||||
db.run_in_transaction(txn)
|
db.run_in_transaction(txn)
|
||||||
|
|
||||||
def post(self):
|
def post(self, blob_ref):
|
||||||
"""Do upload post."""
|
"""Do upload post."""
|
||||||
error_messages = []
|
error_messages = []
|
||||||
|
|
||||||
upload_files = self.get_uploads('file')
|
upload_files = self.get_uploads('file')
|
||||||
|
|
||||||
self.store_blob(upload_files, error_messages)
|
self.store_blob(blob_ref, upload_files, error_messages)
|
||||||
|
|
||||||
if error_messages:
|
if error_messages:
|
||||||
blobstore.delete(upload_files)
|
blobstore.delete(upload_files)
|
||||||
|
@ -275,11 +265,11 @@ class ErrorHandler(webapp.RequestHandler):
|
||||||
|
|
||||||
APP = webapp.WSGIApplication(
|
APP = webapp.WSGIApplication(
|
||||||
[
|
[
|
||||||
('/get', GetHandler),
|
('/get/([^/]+)', GetHandler),
|
||||||
('/check', CheckHandler),
|
('/check/([^/]+)', CheckHandler),
|
||||||
('/list', ListHandler),
|
('/list/([^/]+)', ListHandler),
|
||||||
('/put', GetUploadUrlHandler),
|
('/put/([^/]+)', GetUploadUrlHandler),
|
||||||
('/upload_complete', UploadHandler), # Admin only.
|
('/upload_complete/([^/]+)', UploadHandler), # Admin only.
|
||||||
('/success', SuccessHandler),
|
('/success', SuccessHandler),
|
||||||
('/error', ErrorHandler),
|
('/error', ErrorHandler),
|
||||||
],
|
],
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Example client accesses to blob server using curl.
|
||||||
|
#
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
|
# Put -- 200 response
|
||||||
|
curl -v -L \
|
||||||
|
-F file=@./test_data.txt \
|
||||||
|
http://localhost:8080/put/sha1-126249fd8c18cbb5312a5705746a2af87fba9538
|
||||||
|
|
||||||
|
# Put with bad blob_ref parameter -- 400 response
|
||||||
|
curl -v -L \
|
||||||
|
-F file=@./test_data.txt \
|
||||||
|
http://localhost:8080/put/sha1-22a7fdd575f4c3e7caa3a55cc83db8b8a6714f0f
|
||||||
|
|
||||||
|
# Get present -- the blob
|
||||||
|
curl -v http://localhost:8080/get/\
|
||||||
|
sha1-126249fd8c18cbb5312a5705746a2af87fba9538
|
||||||
|
|
||||||
|
# Get missing -- 404
|
||||||
|
curl -v http://localhost:8080/get/\
|
||||||
|
sha1-22a7fdd575f4c3e7caa3a55cc83db8b8a6714f0f
|
||||||
|
|
||||||
|
# Check present -- 200 with blob ref list response
|
||||||
|
curl -v http://localhost:8080/check/\
|
||||||
|
sha1-126249fd8c18cbb5312a5705746a2af87fba9538
|
||||||
|
|
||||||
|
# Check missing -- 404 with empty list response
|
||||||
|
curl -v http://localhost:8080/check/\
|
||||||
|
sha1-22a7fdd575f4c3e7caa3a55cc83db8b8a6714f0f
|
||||||
|
|
||||||
|
# List -- 200 with list of blobs (just one)
|
||||||
|
curl -v http://localhost:8080/list
|
||||||
|
|
||||||
|
# List offset -- 200 with list of no blobs
|
||||||
|
curl -v http://localhost:8080/list/\
|
||||||
|
sha1-126249fd8c18cbb5312a5705746a2af87fba9538
|
|
@ -0,0 +1 @@
|
||||||
|
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque at tortor in tellus accumsan euismod. Quisque scelerisque velit vel nisi ornare lacinia. Vivamus viverra eleifend congue. Maecenas dolor magna, rhoncus vitae fermentum id, convallis id.
|
Loading…
Reference in New Issue