feat(settings): enhance configuration handling
Updated settings to ensure "ColdBrew" section exists in the config before accessing it. Defaulted `FIELD_ENCRYPTION_KEY` to a generated value if not present and corrected encoding. Made `ALLOWED_HOSTS` configurable via settings file and adjusted `DEBUG` logic to depend on `ALLOWED_HOSTS`.
This commit is contained in:
parent
d2893c3ffa
commit
11e8fe8912
1 changed files with 7 additions and 4 deletions
|
@ -23,15 +23,18 @@ BASE_DIR = Path(__file__).resolve().parent.parent
|
||||||
ASK = AutoSecretKey("settings.ini")
|
ASK = AutoSecretKey("settings.ini")
|
||||||
SECRET_KEY = ASK.secret_key
|
SECRET_KEY = ASK.secret_key
|
||||||
CONFIG = ASK.config
|
CONFIG = ASK.config
|
||||||
DEBUG = CONFIG.getboolean("ColdBrew", "Debug", fallback=False)
|
|
||||||
|
|
||||||
if not (FIELD_ENCRYPTION_KEY := CONFIG.get("ColdBrew", "EncryptionKey")):
|
if "ColdBrew" not in CONFIG:
|
||||||
FIELD_ENCRYPTION_KEY = base64.urlsafe_b64encode(os.urandom(32))
|
CONFIG["ColdBrew"] = {}
|
||||||
|
|
||||||
|
if not (FIELD_ENCRYPTION_KEY := CONFIG.get("ColdBrew", "EncryptionKey", fallback=None)):
|
||||||
|
FIELD_ENCRYPTION_KEY = base64.urlsafe_b64encode(os.urandom(32)).decode()
|
||||||
CONFIG["ColdBrew"]["EncryptionKey"] = FIELD_ENCRYPTION_KEY
|
CONFIG["ColdBrew"]["EncryptionKey"] = FIELD_ENCRYPTION_KEY
|
||||||
ASK.write()
|
ASK.write()
|
||||||
|
|
||||||
ALLOWED_HOSTS = []
|
ALLOWED_HOSTS = CONFIG.get("ColdBrew", "AllowedHosts", fallback="*").split(",")
|
||||||
|
|
||||||
|
DEBUG = CONFIG.getboolean("ColdBrew", "Debug", fallback=False) if ALLOWED_HOSTS else True
|
||||||
|
|
||||||
# Application definition
|
# Application definition
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue