diff options
author | Frederick Muriuki Muriithi | 2024-03-01 09:09:07 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2024-03-01 09:09:07 +0300 |
commit | db51598d41dc8ed415dcd5f957ea66dcf6a0d808 (patch) | |
tree | 628b35d80c98bae70f9d4749566a6992358a6348 /gn_auth/__init__.py | |
parent | 740d6550e55b263bbd182acb2f86ba4be64b9120 (diff) | |
download | gn-auth-db51598d41dc8ed415dcd5f957ea66dcf6a0d808.tar.gz |
Configs: Check that all mandatory settings exist and are non-empty.
Diffstat (limited to 'gn_auth/__init__.py')
-rw-r--r-- | gn_auth/__init__.py | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/gn_auth/__init__.py b/gn_auth/__init__.py index 1ff2ad2..05c2aac 100644 --- a/gn_auth/__init__.py +++ b/gn_auth/__init__.py @@ -18,25 +18,19 @@ from .errors import register_error_handlers class ConfigurationError(Exception): """Raised in case of a configuration error.""" -def __check_secret_key__(app: Flask) -> None: - """Verify secret key is not empty.""" - if app.config.get("SECRET_KEY", "") == "": - raise ConfigurationError("The `SECRET_KEY` settings cannot be empty.") - def check_mandatory_settings(app: Flask) -> None: """Verify that mandatory settings are defined in the application""" undefined = tuple( setting for setting in ( "SECRET_KEY", "SQL_URI", "AUTH_DB", "AUTH_MIGRATIONS", "OAUTH2_SCOPE") - if setting not in app.config) + if setting not ( + (confsetting in app.config) and bool(app.config[confsetting]))) if len(undefined) > 0: raise ConfigurationError( - "You must provide values for the following settings: " + + "You must provide (valid) values for the following settings: " + "\t* " + "\n\t* ".join(undefined)) - __check_secret_key__(app) - def override_settings_with_envvars( app: Flask, ignore: tuple[str, ...]=tuple()) -> None: """Override settings in `app` with those in ENVVARS""" |