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

65 lines
1.8 KiB
Python
Raw Normal View History

2022-08-08 16:01:33 +00:00
import sys
from configparser import ConfigParser
from pathlib import Path
2022-08-09 12:46:48 +00:00
def load_config(*files):
2022-08-08 16:01:33 +00:00
config = ConfigParser()
for file in files:
file = Path(file)
if not file.is_file():
2022-08-09 12:46:48 +00:00
print(f"{file} is missing!")
2022-08-08 16:01:33 +00:00
sys.exit(1)
config.read(file)
return config
2022-08-09 12:46:48 +00:00
def get_settings():
config = load_config("settings.ini")
settings = config["Settings"]
return settings
2022-08-08 16:01:33 +00:00
def set_config(app):
2022-08-09 12:46:48 +00:00
config = load_config("secrets.ini", "settings.ini")
2022-08-08 16:01:33 +00:00
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"]
2022-08-08 20:51:52 +00:00
app.config["SECURITY_PASSWORD_LENGTH_MIN"] = settings.getint("SECURITY_PASSWORD_LENGTH_MIN", 15)
2022-08-08 16:01:33 +00:00
# TODO: app.config["SECURITY_LOGIN_USER_TEMPLATE"] =