From 0501b62c8ba5f9bb7dc4c811b45b97ac1c03162b Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Fri, 3 Jan 2020 17:06:18 -0800 Subject: [PATCH] Load secret key in app --- amanuensis/app.py | 5 ++++- amanuensis/cli.py | 10 ++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/amanuensis/app.py b/amanuensis/app.py index 0c87e9c..d5fda82 100644 --- a/amanuensis/app.py +++ b/amanuensis/app.py @@ -1,6 +1,9 @@ from flask import Flask, render_template -app = Flask(__name__) +import config + +app = Flask("amanuensis") +app.secret_key = bytes.fromhex(config.get('secret_key')) @app.route("/") def root(): diff --git a/amanuensis/cli.py b/amanuensis/cli.py index ad012f6..710f7d8 100644 --- a/amanuensis/cli.py +++ b/amanuensis/cli.py @@ -109,8 +109,14 @@ def command_generate_secret(args): @add_argument("-p", "--port", default="5000") def command_run(args): """Runs the default Flask development server""" - from app import app - app.run(host=args.address, port=args.port) + import app + import config + + if config.get("secret_key") is None: + config.logger.error("Can't run server without a secret_key. Run generate-secret first") + return -1 + app.app.run(host=args.address, port=args.port) + @add_argument("--foo", action="store_true") def command_dump(args):