summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvuko <vuko@hackerspace.pl>2020-06-14 08:57:42 +0200
committervuko <vuko@hackerspace.pl>2020-06-14 08:57:42 +0200
commitf99b6c92efa1d13fe04d3b3e449ad07282682010 (patch)
tree536520330a8019fd71f80c920c49850e0ca17069
parent1287aec1b03246354e6917f71bdd7d7350ef1452 (diff)
downloadcheckinator-f99b6c92efa1d13fe04d3b3e449ad07282682010.tar.gz
checkinator-f99b6c92efa1d13fe04d3b3e449ad07282682010.tar.bz2
checkinator-f99b6c92efa1d13fe04d3b3e449ad07282682010.zip
move config loading outside of flask code
-rw-r--r--README.rst4
-rw-r--r--at.cfg.dist26
-rw-r--r--at/web.py20
-rw-r--r--config.dist.yaml44
-rw-r--r--run.py11
5 files changed, 59 insertions, 46 deletions
diff --git a/README.rst b/README.rst
index 28e4f8b..a0414d1 100644
--- a/README.rst
+++ b/README.rst
@@ -8,10 +8,10 @@ Setup
-----
.. code:: bash
- cp at.cfg.dist at.dist
+ cp config.yaml.dist config.yaml
# edit config file using your favourite editor
- $EDITOR at.cfg
+ $EDITOR config.yaml
# create new database file (or copy existing one)
sqlite3 at.db < dbsetup.sql
diff --git a/at.cfg.dist b/at.cfg.dist
deleted file mode 100644
index 3f32ce2..0000000
--- a/at.cfg.dist
+++ /dev/null
@@ -1,26 +0,0 @@
-DB = './at.db'
-DEBUG = False
-CAP_FILE = './dhcp-cap'
-LEASE_FILE = './dhcpd.leases'
-LEASE_OFFSET = -60 * 60
-TIMEOUT = 1500
-
-WIKI_URL = 'https://wiki.hackerspace.pl/people:%(login)s:start'
-
-CLAIMABLE_PREFIX = '10.8.0.'
-CLAIMABLE_EXCLUDE = [
- # '127.0.0.1',
-]
-
-SECRET_KEY = 'CHANGEME'
-
-SPACEAUTH_CONSUMER_KEY = 'checkinator'
-SPACEAUTH_CONSUMER_SECRET = 'CHANGEME'
-
-SPECIAL_DEVICES = {
- 'kektops': ('90:e6:ba:84'),
- 'esps': ('ec:fa:bc', 'dc:4f:22', 'd8:a0:1d', 'b4:e6:2d', 'ac:d0:74', 'a4:7b:9d', 'a0:20:a6', '90:97:d5', '68:c6:3a', '60:01:94', '5c:cf:7f', '54:5a:a6', '30:ae:a4', '2c:3a:e8', '24:b2:de', '24:0a:c4', '18:fe:34', '38:2b:78', 'bc:dd:c2:'),
- 'vms': ('52:54:00'), # craptrap VMs
-}
-
-PROXY_FIX = False
diff --git a/at/web.py b/at/web.py
index a6c0023..fc82b9f 100644
--- a/at/web.py
+++ b/at/web.py
@@ -7,7 +7,6 @@ from functools import wraps
from flask import Flask, render_template, abort, g, \
redirect, request, url_for, make_response
-from .dhcp import DhcpdUpdater
from spaceauth import SpaceAuth, login_required, current_user, cap_required
@@ -39,12 +38,12 @@ def get_device_infos(conn, hwaddrs):
ignored = row['ignored']
yield DeviceInfo(row['hwaddr'], row['name'], owner, ignored)
-def app(instance_path):
+def app(instance_path, devices_api, config):
app = Flask('at', instance_path=instance_path, instance_relative_config=True)
- app.config.from_pyfile('at.cfg')
+ app.config.update(config)
app.jinja_env.add_extension('jinja2.ext.i18n')
app.jinja_env.install_null_translations()
- app.updater = None
+ app.updater = devices_api
if app.config.get('PROXY_FIX'):
from werkzeug.contrib.fixers import ProxyFix
@@ -219,19 +218,6 @@ def app(instance_path):
data = now_at()
return render_template('admin.html', data=data)
-
- #@app.before_first_request
- def setup():
- updater = DhcpdUpdater(app.config['LEASE_FILE'], app.config['TIMEOUT'],
- app.config['LEASE_OFFSET'])
- app.logger.info('parsing leases file for the first time')
- updater._trigger_update()
- app.logger.info('leases file parsed')
- updater.start()
- app.updater = updater
-
- setup()
-
return app
if __name__ == '__main__':
diff --git a/config.dist.yaml b/config.dist.yaml
new file mode 100644
index 0000000..de8b8a2
--- /dev/null
+++ b/config.dist.yaml
@@ -0,0 +1,44 @@
+DB: 'at.db'
+DEBUG: false
+CAP_FILE: './dhcp-cap'
+LEASE_FILE: './dhcpd.leases'
+LEASE_OFFSET: -3600
+TIMEOUT: 1500
+
+WIKI_URL: 'https://wiki.hackerspace.pl/people:%(login)s:start'
+
+CLAIMABLE_PREFIX: '10.8.0.'
+CLAIMABLE_EXCLUDE: [ ]
+
+SECRET_KEY: 'CHANGEME'
+
+SPACEAUTH_CONSUMER_KEY: 'checkinator'
+SPACEAUTH_CONSUMER_SECRET: 'CHANGEME'
+
+SPECIAL_DEVICES:
+ 'kektops':
+ - '90:e6:ba:84'
+ 'esps':
+ - 'ec:fa:bc'
+ - 'dc:4f:22'
+ - 'd8:a0:1d'
+ - 'b4:e6:2d'
+ - 'ac:d0:74'
+ - 'a4:7b:9d'
+ - 'a0:20:a6'
+ - '90:97:d5'
+ - '68:c6:3a'
+ - '60:01:94'
+ - '5c:cf:7f'
+ - '54:5a:a6'
+ - '30:ae:a4'
+ - '2c:3a:e8'
+ - '24:b2:de'
+ - '24:0a:c4'
+ - '18:fe:34'
+ - '38:2b:78'
+ - 'bc:dd:c2:'
+ 'vms':
+ - '52:54:00' # craptrap VMs
+
+PROXY_FIX: false
diff --git a/run.py b/run.py
index ff961ec..2f9a25b 100644
--- a/run.py
+++ b/run.py
@@ -1,5 +1,14 @@
"""Entry point for running flask application"""
import at.web
+from at.dhcp import DhcpdUpdater
from pathlib import Path
-app = at.web.app(Path(__file__).parent)
+import yaml
+
+config = yaml.safe_load(Path('config.yaml').read_text())
+
+updater = DhcpdUpdater(
+ config['LEASE_FILE'], config['TIMEOUT'], config['LEASE_OFFSET'])
+
+updater.start()
+app = at.web.app(Path(__file__).parent, updater, config)