summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Ipsum <richardipsum@fastmail.co.uk>2014-04-15 17:17:40 +0100
committerRichard Ipsum <richardipsum@fastmail.co.uk>2014-04-15 17:17:40 +0100
commitacefe33868585cf31cda53474a3004da42e00896 (patch)
tree17fbaddabf79843d91f4a7ba3180a54b0ea51d41
parentcc5f95fa563c4817cdcffc428da18e263bd02ae2 (diff)
parent15b7e4fad677c127d4011babc01f7e4a71f259d8 (diff)
downloadmorph-cache-server-acefe33868585cf31cda53474a3004da42e00896.tar.gz
Merge branch 'baserock/richardipsum/post_artifacts5'
Reviewed by: Lars Wirzenius Daniel Silverstone (on IRC) Sam Thursfield (v4 of patch) Richard Maw (on IRC)
-rwxr-xr-xmorph-cache-server34
1 files changed, 31 insertions, 3 deletions
diff --git a/morph-cache-server b/morph-cache-server
index dbf6785..a3c3c97 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,12 +303,40 @@ 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.load(request.body)
+ results = {}
+
+ logging.debug('Received a POST request for /artifacts')
+
+ for artifact in artifacts:
+ if artifact.startswith('/'):
+ response.status = 500
+ logging.error("%s: artifact name cannot start with a '/'"
+ % artifact)
+ return
+
+ filename = os.path.join(self.settings['artifact-dir'], artifact)
+ results[artifact] = os.path.exists(filename)
+
+ if results[artifact]:
+ logging.debug('%s is in the cache', artifact)
+ else:
+ logging.debug('%s is NOT in the cache', artifact)
+
+ return results
+
root = Bottle()
root.mount(app, '/1.0')
- if self.settings['fcgi-server']:
+ if self.settings['fcgi-server']:
WSGIServer(root).run()
else:
run(root, host='0.0.0.0', port=self.settings['port'], reloader=True)