mirror of
https://github.com/optim-enterprises-bv/Mailu.git
synced 2025-11-01 18:47:52 +00:00
Unify and coerce booleans from env used in admin
At some places, the string that DOMAIN_REGISTRATION is got used like a boolean (an easy misassumption to make while in python and dealing with the config dict), making `DOMAIN_REGISTRATION=False` act as a truthy value. To stop such future problems from happening, coerce environment config strings to real bools. closes #830
This commit is contained in:
@@ -30,11 +30,11 @@ DEFAULT_CONFIG = {
|
||||
'POSTMASTER': 'postmaster',
|
||||
'TLS_FLAVOR': 'cert',
|
||||
'AUTH_RATELIMIT': '10/minute;1000/hour',
|
||||
'DISABLE_STATISTICS': 'False',
|
||||
'DISABLE_STATISTICS': False,
|
||||
# Mail settings
|
||||
'DMARC_RUA': None,
|
||||
'DMARC_RUF': None,
|
||||
'WELCOME': 'False',
|
||||
'WELCOME': False,
|
||||
'WELCOME_SUBJECT': 'Dummy welcome topic',
|
||||
'WELCOME_BODY': 'Dummy welcome body',
|
||||
'DKIM_SELECTOR': 'dkim',
|
||||
@@ -74,13 +74,21 @@ class ConfigManager(dict):
|
||||
def __init__(self):
|
||||
self.config = dict()
|
||||
|
||||
def __coerce_value(self, value):
|
||||
if isinstance(value, str) and value.lower() in ('true','yes'):
|
||||
return True
|
||||
elif isinstance(value, str) and value.lower() in ('false', 'no'):
|
||||
return False
|
||||
return value
|
||||
|
||||
def init_app(self, app):
|
||||
self.config.update(app.config)
|
||||
# get environment variables
|
||||
self.config.update({
|
||||
key: os.environ.get(key, value)
|
||||
key: self.__coerce_value(os.environ.get(key, value))
|
||||
for key, value in DEFAULT_CONFIG.items()
|
||||
})
|
||||
|
||||
# automatically set the sqlalchemy string
|
||||
if self.config['DB_FLAVOR']:
|
||||
template = self.DB_TEMPLATES[self.config['DB_FLAVOR']]
|
||||
|
||||
Reference in New Issue
Block a user