1
0
mirror of https://github.com/IEEE-SB-Passau/pelican-deployment-system.git synced 2017-09-06 16:35:38 +02:00

make auth optional

This commit is contained in:
2016-06-16 23:42:28 +02:00
parent 32db01ccfc
commit 5de90f0699
3 changed files with 16 additions and 8 deletions

3
app.py
View File

@@ -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)

View File

@@ -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"

View File

@@ -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('/<name>')
@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('/<name>/rerun')
def rerun(name):
runner = _get_runner(name)