From 68d9fb37552266809d63732f7e82e4b9040713c8 Mon Sep 17 00:00:00 2001 From: Rauno Tuul Date: Wed, 8 Mar 2023 12:08:07 +0200 Subject: [PATCH] Support multiple Flask session types, not just filesystem. Set via generic SESSION_TYPE environment variable --- configs/development.py | 2 +- configs/docker_config.py | 6 +++--- docs/wiki/configuration/Environment-variables.md | 2 +- powerdnsadmin/__init__.py | 6 ++---- powerdnsadmin/default_config.py | 3 ++- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/configs/development.py b/configs/development.py index b848d0c..103656a 100644 --- a/configs/development.py +++ b/configs/development.py @@ -24,7 +24,7 @@ CAPTCHA_SESSION_KEY = 'captcha_image' #Server side sessions tracking #Set to TRUE for CAPTCHA, or enable another stateful session tracking system -FILESYSTEM_SESSIONS_ENABLED = True +SESSION_TYPE = 'filesystem' ### DATABASE - MySQL #SQLALCHEMY_DATABASE_URI = 'mysql://{}:{}@{}/{}'.format( diff --git a/configs/docker_config.py b/configs/docker_config.py index 0d006bd..f045e95 100644 --- a/configs/docker_config.py +++ b/configs/docker_config.py @@ -4,7 +4,7 @@ PORT = 80 SQLALCHEMY_DATABASE_URI = 'sqlite:////data/powerdns-admin.db' SESSION_COOKIE_SAMESITE = 'Lax' CSRF_COOKIE_HTTPONLY = True -FILESYSTEM_SESSIONS_ENABLED = True +SESSION_TYPE = 'filesystem' legal_envvars = ( 'SECRET_KEY', @@ -68,7 +68,7 @@ legal_envvars = ( 'LDAP_ENABLED', 'SAML_CERT', 'SAML_KEY', - 'FILESYSTEM_SESSIONS_ENABLED', + 'SESSION_TYPE', 'SESSION_COOKIE_SECURE', 'CSRF_COOKIE_SECURE', 'CAPTCHA_ENABLE', @@ -93,7 +93,7 @@ legal_envvars_bool = ( 'SIGNUP_ENABLED', 'LOCAL_DB_ENABLED', 'LDAP_ENABLED', - 'FILESYSTEM_SESSIONS_ENABLED', + 'SESSION_TYPE', 'SESSION_COOKIE_SECURE', 'CSRF_COOKIE_SECURE', 'CAPTCHA_ENABLE', diff --git a/docs/wiki/configuration/Environment-variables.md b/docs/wiki/configuration/Environment-variables.md index b133ee6..fbbedac 100644 --- a/docs/wiki/configuration/Environment-variables.md +++ b/docs/wiki/configuration/Environment-variables.md @@ -4,7 +4,7 @@ | ---------| ----------- | -------- | ------------- | | BIND_ADDRESS | | CSRF_COOKIE_SECURE | -| FILESYSTEM_SESSIONS_ENABLED | +| SESSION_TYPE | null|filesystem|sqlalchemy | | filesystem | | LDAP_ENABLED | | LOCAL_DB_ENABLED | | LOG_LEVEL | diff --git a/powerdnsadmin/__init__.py b/powerdnsadmin/__init__.py index 0b2c5a1..f3bca83 100755 --- a/powerdnsadmin/__init__.py +++ b/powerdnsadmin/__init__.py @@ -56,10 +56,8 @@ def create_app(config=None): _sslify = SSLify(app) # lgtm [py/unused-local-variable] # Load Flask-Session - if app.config.get('FILESYSTEM_SESSIONS_ENABLED'): - app.config['SESSION_TYPE'] = 'filesystem' - sess = Session() - sess.init_app(app) + sess = Session() + sess.init_app(app) # SMTP app.mail = Mail(app) diff --git a/powerdnsadmin/default_config.py b/powerdnsadmin/default_config.py index 8513915..07de0f3 100644 --- a/powerdnsadmin/default_config.py +++ b/powerdnsadmin/default_config.py @@ -8,7 +8,8 @@ SECRET_KEY = 'e951e5a1f4b94151b360f47edf596dd2' BIND_ADDRESS = '0.0.0.0' PORT = 9191 HSTS_ENABLED = False -FILESYSTEM_SESSIONS_ENABLED = True + +SESSION_TYPE = 'filesystem' SESSION_COOKIE_SAMESITE = 'Lax' CSRF_COOKIE_HTTPONLY = True