summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <daniel.silverstone@codethink.co.uk>2012-09-07 10:14:27 +0100
committerDaniel Silverstone <daniel.silverstone@codethink.co.uk>2012-09-07 13:42:08 +0100
commit9c3279221262057c7eb8ebdcb29f366dc4de66d5 (patch)
treef47e356a0c5a0d15f9a62cf08458d669dde358bb
parentc2998750dbb3d79b7455a079aa3f3d243715a15f (diff)
downloadmorph-9c3279221262057c7eb8ebdcb29f366dc4de66d5.tar.gz
Add ability to have 'writable' cache servers.
Since we need to be able to update the cache from builders, this patch introduces a --enable-writes argument to morph-cache-server and also adds a @writable decorator to the class ready for marking particular paths which are only available when --enable-writes is set.
-rwxr-xr-xmorph-cache-server19
1 files changed, 19 insertions, 0 deletions
diff --git a/morph-cache-server b/morph-cache-server
index 827da10a..ba5f0b2a 100755
--- a/morph-cache-server
+++ b/morph-cache-server
@@ -55,6 +55,8 @@ class MorphCacheServer(cliapp.Application):
default=defaults['artifact-dir'])
self.settings.boolean(['direct-mode'],
'cache directories are directly managed')
+ self.settings.boolean(['enable-writes'],
+ 'enable the write methods (fetch and delete)')
def process_args(self, args):
app = Bottle()
@@ -64,6 +66,23 @@ class MorphCacheServer(cliapp.Application):
self.settings['bundle-dir'],
self.settings['direct-mode'])
+ def writable(prefix):
+ """Selectively enable bottle prefixes.
+
+ prefix -- The path prefix we are enabling
+
+ If the runtime configuration setting --enable-writes is provided
+ then we return the app.get() decorator for the given path prefix
+ otherwise we return a lambda which passes the function through
+ undecorated.
+
+ This has the effect of being a runtime-enablable @app.get(...)
+
+ """
+ if self.settings['enable-writes']:
+ return app.get(prefix)
+ return lambda fn: fn
+
@app.get('/sha1s')
def sha1():
repo = self._unescape_parameter(request.query.repo)