Add configuration file checker

This commit is contained in:
Théophile Bastian 2018-03-03 02:48:09 +01:00
parent dfa4359f23
commit ec1c2508d2
2 changed files with 23 additions and 1 deletions

View file

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

View file

@ -4,3 +4,4 @@ itsdangerous==0.24
Jinja2==2.10
MarkupSafe==1.0
Werkzeug==0.14.1
termcolor==1.1.0