Skip to content

Commit eb11b24

Browse files
authored
refactor: TT-114 Refactor in the validation of environment variables classes in backend (#258)
1 parent 21713ff commit eb11b24

File tree

4 files changed

+22
-25
lines changed

4 files changed

+22
-25
lines changed

commons/feature_toggles/feature_toggle_manager.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,11 @@
22
import json
33
from time_tracker_api.security import current_user_email
44
from azure.appconfiguration import AzureAppConfigurationClient
5+
from utils.environment_variables import check_variables_are_defined
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_variables_are_defined(['AZURE_APP_CONFIGURATION_CONNECTION_STRING'])
1810
AZURE_APP_CONFIGURATION_CONNECTION_STRING = os.environ.get(
1911
'AZURE_APP_CONFIGURATION_CONNECTION_STRING'
2012
)

requirements/time_tracker_api/dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ pytest-mock==2.0.0
1515
coverage==4.5.1
1616

1717
# Git hooks
18-
pre-commit==2.2.0
18+
pre-commit==2.2.0

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.environment_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+
ms_variables = [
11+
'MS_CLIENT_ID',
12+
'MS_AUTHORITY',
13+
'MS_SECRET',
14+
'MS_SCOPE',
15+
'MS_ENDPOINT',
16+
]
17+
18+
check_variables_are_defined(ms_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/environment_variables.py

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

0 commit comments

Comments
 (0)