From aa709519642dcd3f65c2bbbe6c51c98a0d56549b Mon Sep 17 00:00:00 2001 From: Rauno Tuul Date: Wed, 8 Mar 2023 17:05:32 +0200 Subject: [PATCH] Read flask session type from environment variable and create sessions table if not exist. --- configs/docker_config.py | 1 - powerdnsadmin/__init__.py | 11 +++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/configs/docker_config.py b/configs/docker_config.py index f045e95..030e8d2 100644 --- a/configs/docker_config.py +++ b/configs/docker_config.py @@ -93,7 +93,6 @@ legal_envvars_bool = ( 'SIGNUP_ENABLED', 'LOCAL_DB_ENABLED', 'LDAP_ENABLED', - 'SESSION_TYPE', 'SESSION_COOKIE_SECURE', 'CSRF_COOKIE_SECURE', 'CAPTCHA_ENABLE', diff --git a/powerdnsadmin/__init__.py b/powerdnsadmin/__init__.py index f3bca83..d447a00 100755 --- a/powerdnsadmin/__init__.py +++ b/powerdnsadmin/__init__.py @@ -56,8 +56,15 @@ def create_app(config=None): _sslify = SSLify(app) # lgtm [py/unused-local-variable] # Load Flask-Session - sess = Session() - sess.init_app(app) + app.config['SESSION_TYPE'] = app.config.get('SESSION_TYPE') + if 'SESSION_TYPE' in os.environ: + app.config['SESSION_TYPE'] = os.environ.get('SESSION_TYPE') + + sess = Session(app) + + # create sessions table if using sqlalchemy backend + if os.environ.get('SESSION_TYPE') == 'sqlalchemy': + sess.app.session_interface.db.create_all() # SMTP app.mail = Mail(app)