diff --git a/gogsmaker.py b/gogsmaker.py index 9375167..7005afb 100644 --- a/gogsmaker.py +++ b/gogsmaker.py @@ -9,6 +9,7 @@ import hmac from hashlib import sha256 from threading import Thread from functools import wraps +from termcolor import colored from flask import Flask, request from . import settings @@ -138,4 +139,24 @@ def view_root(payload, hook): return 'OK\n', 200 -# TODO: @app.before_first_request settings checkup +@app.before_first_request # FIXME this should be run on startup... +def check_settings(): + ''' Check the supplied settings ''' + if settings.DEBUG: + print(colored('WARNING! ', 'red', attrs=['bold']) + + 'GogsMaker is running in DEBUG MODE, this is unsuitable for ' + + 'production environments!') + + required_keys = ['name', 'url', 'targets', 'secret'] + for hook_id, hook in enumerate(settings.HOOKS): + for key in required_keys: + if key not in hook: + if key == 'name': + descr = '#{}'.format(hook_id) + else: + descr = '{} (#{})'.format(hook['name'], hook_id) + + print((colored('FATAL! ', 'red', attrs=['bold']) + + 'Configuration error: hook {} lacks attribute {}.') + .format(descr, key)) + sys.exit(1) diff --git a/requirements.txt b/requirements.txt index 30dde8b..a9c542b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ itsdangerous==0.24 Jinja2==2.10 MarkupSafe==1.0 Werkzeug==0.14.1 +termcolor==1.1.0