summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Ipsum <richard.ipsum@codethink.co.uk>2014-04-03 14:41:31 +0100
committerRichard Ipsum <richard.ipsum@codethink.co.uk>2014-04-08 10:14:37 +0100
commit6766edc490a233e03c65f5c55e38b57b46dda290 (patch)
treea60b3f9daa3afdd124e020c1b4e2e4a1ea31899c
parentcc5f95fa563c4817cdcffc428da18e263bd02ae2 (diff)
downloadmorph-cache-server-baserock/richardipsum/post_artifacts3.tar.gz
Add post request for /artifactsbaserock/richardipsum/post_artifacts3
With this we can request the state of a set of artifacts in a single request. Artifacts are sent as a json array. We check whether each artifact is in the cache or not and send our findings back to the client as a json object.
-rwxr-xr-xmorph-cache-server24
1 files changed, 22 insertions, 2 deletions
diff --git a/morph-cache-server b/morph-cache-server
index dbf6785..2968359 100755
--- a/morph-cache-server
+++ b/morph-cache-server
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
-# Copyright (C) 2013 Codethink Limited
+# Copyright (C) 2013, 2014 Codethink Limited
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -303,7 +303,27 @@ class MorphCacheServer(cliapp.Application):
else:
response.status = 404
logging.debug('artifact %s does not exist' % basename)
-
+
+ @app.post('/artifacts')
+ def post_artifacts():
+ if request.content_type != 'application/json':
+ logging.warning('Content-type is not json: '
+ 'expecting a json post request')
+
+ artifacts = json.loads(request.body.read())
+ results = {}
+
+ logging.debug('Received a POST request for /artifacts')
+
+ for artifact in artifacts:
+ filename = os.path.join(self.settings['artifact-dir'], artifact)
+ results[artifact] = os.path.exists(filename)
+
+ logging.debug('%s is%s in the cache' %
+ (artifact, '' if results[artifact] else "n't"))
+
+ return results
+
root = Bottle()
root.mount(app, '/1.0')