diff --git a/app.py b/app.py index f56eb94..d63639c 100755 --- a/app.py +++ b/app.py @@ -50,8 +50,7 @@ def init_app(configpath): default_app().mount("/hooks/", pelican_deploy.webhookbottle.app) pelican_deploy.statusbottle.set_auth_basic_fn(getattr(config, - "STATUS_AUTH_BASIC_FN", - lambda us, pw: False)) + "STATUS_AUTH_BASIC_FN", None)) pelican_deploy.statusbottle.set_runners(**runners) default_app().mount("/status/", pelican_deploy.statusbottle.app) diff --git a/example_config.py b/example_config.py index 3dc2277..862b1b8 100644 --- a/example_config.py +++ b/example_config.py @@ -66,7 +66,7 @@ SCHEDULED_BUILD_JOBS = [ ] -# username, password for /status/... subpages, accepts nothing if not set +# user, pass for /status/... subpages, if not set or None no auth is done def STATUS_AUTH_BASIC_FN(user, passw): return user == "powerpoint" and passw == "karaoke" diff --git a/pelican_deploy/statusbottle.py b/pelican_deploy/statusbottle.py index cbfcb69..6ea1b3c 100644 --- a/pelican_deploy/statusbottle.py +++ b/pelican_deploy/statusbottle.py @@ -1,6 +1,7 @@ -from bottle import route, template, request, post, Bottle, HTTPError,auth_basic +from bottle import route, template, request, post, Bottle, HTTPError, auth_basic from pprint import pformat from itertools import islice +from functools import wraps import logging import sys @@ -9,8 +10,16 @@ log = logging.getLogger(__name__) app = Bottle() -def _auth_basic_fn(us, pw): - return app.config.get("auth_basic_fn", lambda us, pw: False)(us, pw) +def _auth_basic(fn): + @wraps(fn) + def wrapper(*args, **kwargs): + authfn = app.config.get("auth_basic_fn") + if authfn: + return auth_basic(authfn)(fn)(*args, **kwargs) + else: + return fn(*args, **kwargs) + return wrapper + def set_runners(**name_runner_mapping): app.config["deploy.runners"] = name_runner_mapping @@ -56,7 +65,7 @@ def status(): return template(tpl, runners=app.config["deploy.runners"].values()) @app.route('/') -@auth_basic(_auth_basic_fn) +@_auth_basic def runnerstatus(name): runner = _get_runner(name) rerun = "rerun" in request.query @@ -89,7 +98,7 @@ def runnerstatus(name): return template(tpl, runner=runner, bss=runner.build_status, islice=islice, pformat=pformat, start=start, end=end) -@auth_basic(_auth_basic_fn) +@_auth_basic @app.route('//rerun') def rerun(name): runner = _get_runner(name)