1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-11-08 21:21:06 +00:00
AdvLabDB/advlabdb/config.py
2022-08-08 22:51:52 +02:00

59 lines
1.7 KiB
Python

import sys
from configparser import ConfigParser
from pathlib import Path
def load_config(app, *files):
config = ConfigParser()
for file in files:
file = Path(file)
if not file.is_file():
app.logger.critical(str(file) + " is missing")
sys.exit(1)
config.read(file)
return config
def set_config(app):
config = load_config(app, "secrets.ini", "settings.ini")
secrets = config["Secrets"]
settings = config["Settings"]
app.config["SECRET_KEY"] = secrets["SECRET_KEY"]
# SQLALCHEMY
db_file = Path(settings["SQLITE_DB_PATH"])
db_file.parent.mkdir(parents=True, exist_ok=True)
app.config["SQLALCHEMY_DATABASE_URI"] = f"sqlite:///{db_file}"
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
# Flask-Admin
app.config["FLASK_ADMIN_FLUID_LAYOUT"] = True
# Flask-Security
# Enable features
app.config["SECURITY_TRACKABLE"] = True
# Explicitly disable features
app.config["SECURITY_CONFIRMABLE"] = False
app.config["SECURITY_REGISTERABLE"] = False
app.config["SECURITY_RECOVERABLE"] = False
app.config["SECURITY_PASSWORDLESS"] = False
app.config["SECURITY_CHANGEABLE"] = False
app.config["SECURITY_TWO_FACTOR"] = False
app.config["SECURITY_UNIFIED_SIGNIN"] = False
check_email_deliverability = settings.getboolean("CHECK_EMAIL_DELIVERABILITY", True)
app.config["SECURITY_EMAIL_VALIDATOR_ARGS"] = {
"check_deliverability": check_email_deliverability,
}
app.config["SECURITY_PASSWORD_SALT"] = secrets["SECURITY_PASSWORD_SALT"]
app.config["SECURITY_PASSWORD_LENGTH_MIN"] = settings.getint("SECURITY_PASSWORD_LENGTH_MIN", 15)
# TODO: app.config["SECURITY_LOGIN_USER_TEMPLATE"] =
return settings