From 9c3279221262057c7eb8ebdcb29f366dc4de66d5 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Fri, 7 Sep 2012 10:14:27 +0100 Subject: 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. --- morph-cache-server | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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) -- cgit v1.2.1