@ -30,11 +30,11 @@ DEFAULT_CONFIG = {
' POSTMASTER ' : ' postmaster ' ,
' POSTMASTER ' : ' postmaster ' ,
' TLS_FLAVOR ' : ' cert ' ,
' TLS_FLAVOR ' : ' cert ' ,
' AUTH_RATELIMIT ' : ' 10/minute;1000/hour ' ,
' AUTH_RATELIMIT ' : ' 10/minute;1000/hour ' ,
' DISABLE_STATISTICS ' : ' False ' ,
' DISABLE_STATISTICS ' : False ,
# Mail settings
# Mail settings
' DMARC_RUA ' : None ,
' DMARC_RUA ' : None ,
' DMARC_RUF ' : None ,
' DMARC_RUF ' : None ,
' WELCOME ' : ' False ' ,
' WELCOME ' : False ,
' WELCOME_SUBJECT ' : ' Dummy welcome topic ' ,
' WELCOME_SUBJECT ' : ' Dummy welcome topic ' ,
' WELCOME_BODY ' : ' Dummy welcome body ' ,
' WELCOME_BODY ' : ' Dummy welcome body ' ,
' DKIM_SELECTOR ' : ' dkim ' ,
' DKIM_SELECTOR ' : ' dkim ' ,
@ -74,13 +74,21 @@ class ConfigManager(dict):
def __init__ ( self ) :
def __init__ ( self ) :
self . config = dict ( )
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 ) :
def init_app ( self , app ) :
self . config . update ( app . config )
self . config . update ( app . config )
# get environment variables
# get environment variables
self . config . update ( {
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 ( )
for key , value in DEFAULT_CONFIG . items ( )
} )
} )
# automatically set the sqlalchemy string
# automatically set the sqlalchemy string
if self . config [ ' DB_FLAVOR ' ] :
if self . config [ ' DB_FLAVOR ' ] :
template = self . DB_TEMPLATES [ self . config [ ' DB_FLAVOR ' ] ]
template = self . DB_TEMPLATES [ self . config [ ' DB_FLAVOR ' ] ]