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:
3
app.py
3
app.py
@@ -50,8 +50,7 @@ def init_app(configpath):
|
|||||||
default_app().mount("/hooks/", pelican_deploy.webhookbottle.app)
|
default_app().mount("/hooks/", pelican_deploy.webhookbottle.app)
|
||||||
|
|
||||||
pelican_deploy.statusbottle.set_auth_basic_fn(getattr(config,
|
pelican_deploy.statusbottle.set_auth_basic_fn(getattr(config,
|
||||||
"STATUS_AUTH_BASIC_FN",
|
"STATUS_AUTH_BASIC_FN", None))
|
||||||
lambda us, pw: False))
|
|
||||||
pelican_deploy.statusbottle.set_runners(**runners)
|
pelican_deploy.statusbottle.set_runners(**runners)
|
||||||
default_app().mount("/status/", pelican_deploy.statusbottle.app)
|
default_app().mount("/status/", pelican_deploy.statusbottle.app)
|
||||||
|
|
||||||
|
|||||||
@@ -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):
|
def STATUS_AUTH_BASIC_FN(user, passw):
|
||||||
return user == "powerpoint" and passw == "karaoke"
|
return user == "powerpoint" and passw == "karaoke"
|
||||||
|
|
||||||
|
|||||||
@@ -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 pprint import pformat
|
||||||
from itertools import islice
|
from itertools import islice
|
||||||
|
from functools import wraps
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
@@ -9,8 +10,16 @@ log = logging.getLogger(__name__)
|
|||||||
app = Bottle()
|
app = Bottle()
|
||||||
|
|
||||||
|
|
||||||
def _auth_basic_fn(us, pw):
|
def _auth_basic(fn):
|
||||||
return app.config.get("auth_basic_fn", lambda us, pw: False)(us, pw)
|
@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):
|
def set_runners(**name_runner_mapping):
|
||||||
app.config["deploy.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())
|
return template(tpl, runners=app.config["deploy.runners"].values())
|
||||||
|
|
||||||
@app.route('/<name>')
|
@app.route('/<name>')
|
||||||
@auth_basic(_auth_basic_fn)
|
@_auth_basic
|
||||||
def runnerstatus(name):
|
def runnerstatus(name):
|
||||||
runner = _get_runner(name)
|
runner = _get_runner(name)
|
||||||
rerun = "rerun" in request.query
|
rerun = "rerun" in request.query
|
||||||
@@ -89,7 +98,7 @@ def runnerstatus(name):
|
|||||||
return template(tpl, runner=runner, bss=runner.build_status, islice=islice,
|
return template(tpl, runner=runner, bss=runner.build_status, islice=islice,
|
||||||
pformat=pformat, start=start, end=end)
|
pformat=pformat, start=start, end=end)
|
||||||
|
|
||||||
@auth_basic(_auth_basic_fn)
|
@_auth_basic
|
||||||
@app.route('/<name>/rerun')
|
@app.route('/<name>/rerun')
|
||||||
def rerun(name):
|
def rerun(name):
|
||||||
runner = _get_runner(name)
|
runner = _get_runner(name)
|
||||||
|
|||||||
Reference in New Issue
Block a user