From db51598d41dc8ed415dcd5f957ea66dcf6a0d808 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Fri, 1 Mar 2024 09:09:07 +0300 Subject: Configs: Check that all mandatory settings exist and are non-empty. --- gn_auth/__init__.py | 12 +++--------- 1 file 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""" -- cgit v1.2.3