Skip to content

Commit d09481d

Browse files
committed
fix: TT-114 Refactor in the validation of environment variables classes in backend
1 parent 21713ff commit d09481d

File tree

3 files changed

+22
-25
lines changed

3 files changed

+22
-25
lines changed

commons/feature_toggles/feature_toggle_manager.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,10 @@
22
import json
33
from time_tracker_api.security import current_user_email
44
from azure.appconfiguration import AzureAppConfigurationClient
5-
5+
from utils.check_variables import check_variables_are_defined
66

77
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()
8+
check_variables_are_defined(['AZURE_APP_CONFIGURATION_CONNECTION_STRING'])
189
AZURE_APP_CONFIGURATION_CONNECTION_STRING = os.environ.get(
1910
'AZURE_APP_CONFIGURATION_CONNECTION_STRING'
2011
)

utils/azure_users.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,20 @@
33
import requests
44
import json
55
from typing import List
6+
from utils.check_variables import check_variables_are_defined
67

78

89
class MSConfig:
9-
def check_variables_are_defined():
10-
auth_variables = [
11-
'MS_CLIENT_ID',
12-
'MS_AUTHORITY',
13-
'MS_SECRET',
14-
'MS_SCOPE',
15-
'MS_ENDPOINT',
16-
]
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-
)
10+
auth_variables = [
11+
'MS_CLIENT_ID',
12+
'MS_AUTHORITY',
13+
'MS_SECRET',
14+
'MS_SCOPE',
15+
'MS_ENDPOINT',
16+
]
17+
18+
check_variables_are_defined(auth_variables)
2219

23-
check_variables_are_defined()
2420
CLIENT_ID = os.environ.get('MS_CLIENT_ID')
2521
AUTHORITY = os.environ.get('MS_AUTHORITY')
2622
SECRET = os.environ.get('MS_SECRET')

utils/check_variables.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import os
2+
3+
def check_variables_are_defined(variables):
4+
for var in variables:
5+
if var not in os.environ:
6+
raise EnvironmentError(
7+
"{} is not defined in the environment".format(var)
8+
)
9+
10+

0 commit comments

Comments
 (0)