diff --git a/commons/feature_toggles/feature_toggle_manager.py b/commons/feature_toggles/feature_toggle_manager.py index 9d240b49..6549380e 100644 --- a/commons/feature_toggles/feature_toggle_manager.py +++ b/commons/feature_toggles/feature_toggle_manager.py @@ -2,19 +2,10 @@ import json from time_tracker_api.security import current_user_email from azure.appconfiguration import AzureAppConfigurationClient - +from utils.check_variables import check_variables_are_defined class FeatureToggleConfig: - def check_variables_are_defined(): - azure_app_variable = 'AZURE_APP_CONFIGURATION_CONNECTION_STRING' - if azure_app_variable not in os.environ: - raise EnvironmentError( - "{} is not defined in the environment".format( - azure_app_variable - ) - ) - - check_variables_are_defined() + check_variables_are_defined(['AZURE_APP_CONFIGURATION_CONNECTION_STRING']) AZURE_APP_CONFIGURATION_CONNECTION_STRING = os.environ.get( 'AZURE_APP_CONFIGURATION_CONNECTION_STRING' ) diff --git a/utils/azure_users.py b/utils/azure_users.py index 279584b1..970df191 100644 --- a/utils/azure_users.py +++ b/utils/azure_users.py @@ -3,24 +3,20 @@ import requests import json from typing import List +from utils.check_variables import check_variables_are_defined class MSConfig: - def check_variables_are_defined(): - auth_variables = [ - 'MS_CLIENT_ID', - 'MS_AUTHORITY', - 'MS_SECRET', - 'MS_SCOPE', - 'MS_ENDPOINT', - ] - for var in auth_variables: - if var not in os.environ: - raise EnvironmentError( - "{} is not defined in the environment".format(var) - ) + auth_variables = [ + 'MS_CLIENT_ID', + 'MS_AUTHORITY', + 'MS_SECRET', + 'MS_SCOPE', + 'MS_ENDPOINT', + ] + + check_variables_are_defined(auth_variables) - check_variables_are_defined() CLIENT_ID = os.environ.get('MS_CLIENT_ID') AUTHORITY = os.environ.get('MS_AUTHORITY') SECRET = os.environ.get('MS_SECRET') diff --git a/utils/check_variables.py b/utils/check_variables.py new file mode 100644 index 00000000..d9adf347 --- /dev/null +++ b/utils/check_variables.py @@ -0,0 +1,10 @@ +import os + +def check_variables_are_defined(variables): + for var in variables: + if var not in os.environ: + raise EnvironmentError( + "{} is not defined in the environment".format(var) + ) + + \ No newline at end of file