import sys from configparser import ConfigParser from pathlib import Path def load_config(*files): config = ConfigParser() for file in files: file = Path(file) if not file.is_file(): print(f"{file} is missing!") sys.exit(1) config.read(file) return config def get_settings(): config = load_config("settings.ini") settings = config["Settings"] return settings def set_config(app): config = load_config("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"] =