Skip to content

Commit 5929554

Browse files
committed
TT-98 fix: refactor Config class
1 parent 036c8db commit 5929554

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

commons/feature_toggles/feature_toggle_manager.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
import os
22
import json
33
from time_tracker_api.security import current_user_email
4+
from time_tracker_api.config import check_if_env_variables_are_defined
45
from azure.appconfiguration import AzureAppConfigurationClient
56

67

78
class FeatureToggleConfig:
8-
def check_variables_are_defined():
9-
azure_app_variable = 'AZURE_APP_CONFIGURATION_CONNECTION_STRING'
10-
if azure_app_variable not in os.environ:
11-
raise EnvironmentError(
12-
"{} is not defined in the environment".format(
13-
azure_app_variable
14-
)
15-
)
16-
17-
check_variables_are_defined()
9+
check_if_env_variables_are_defined(
10+
env_vars=['AZURE_APP_CONFIGURATION_CONNECTION_STRING']
11+
)
1812
AZURE_APP_CONFIGURATION_CONNECTION_STRING = os.environ.get(
1913
'AZURE_APP_CONFIGURATION_CONNECTION_STRING'
2014
)

time_tracker_api/config.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
DISABLE_STR_VALUES = ("false", "0", "disabled")
66

77

8+
def check_if_env_variables_are_defined(env_vars):
9+
for var in env_vars:
10+
if var not in os.environ:
11+
raise EnvironmentError(
12+
"{} is not defined in the environment".format(var)
13+
)
14+
15+
816
class Config:
917
SECRET_KEY = get_or_generate_dev_secret_key()
1018
SQL_DATABASE_URI = os.environ.get('SQL_DATABASE_URI')

utils/azure_users.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,19 @@
33
import requests
44
import json
55
from typing import List
6+
from time_tracker_api.config import check_if_env_variables_are_defined
67

78

89
class MSConfig:
9-
def check_variables_are_defined():
10-
auth_variables = [
10+
check_if_env_variables_are_defined(
11+
env_vars=[
1112
'MS_CLIENT_ID',
1213
'MS_AUTHORITY',
1314
'MS_SECRET',
1415
'MS_SCOPE',
1516
'MS_ENDPOINT',
1617
]
17-
for var in auth_variables:
18-
if var not in os.environ:
19-
raise EnvironmentError(
20-
"{} is not defined in the environment".format(var)
21-
)
22-
23-
check_variables_are_defined()
18+
)
2419
CLIENT_ID = os.environ.get('MS_CLIENT_ID')
2520
AUTHORITY = os.environ.get('MS_AUTHORITY')
2621
SECRET = os.environ.get('MS_SECRET')

0 commit comments

Comments
 (0)