Skip to content

Commit c46f415

Browse files
authored
validate if db env values exist in .env (#644)
# Purpose Completed TODO in config.py # New Changes - added validation to pulling .env values to ensure that they exist in the .env file # Testing Explain tests that you ran to verify code functionality. - [x] I have unit-tested this PR. Otherwise, explain why it cannot be unit-tested. see screenshot below - [x] I have included screenshots of the tests performed below. <img width="908" height="165" alt="Screenshot 2025-11-25 at 3 12 06 PM" src="https://github.com/user-attachments/assets/ca81a027-af42-44b2-a619-45989bc7136a" />
1 parent fd133e6 commit c46f415

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

gs/backend/config/config.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,27 @@ def __init__(self) -> None:
2222

2323
backend_config = BackendConfiguration()
2424

25-
# TODO: Make these throw an exception if they are None
26-
GS_DATABASE_USER = environ.get("GS_DATABASE_USER")
27-
GS_DATABASE_PASSWORD = environ.get("GS_DATABASE_PASSWORD")
28-
GS_DATABASE_LOCATION = environ.get("GS_DATABASE_LOCATION")
29-
GS_DATABASE_PORT = environ.get("GS_DATABASE_PORT")
30-
GS_DATABASE_NAME = environ.get("GS_DATABASE_NAME")
25+
26+
def getenv(config: str) -> str:
27+
"""
28+
Validates whether or not database env values exist in .env. If not, throws a value error.
29+
30+
:param config: Variable in .env
31+
:type config: str
32+
:return: Value of variable in .env
33+
:rtype: str
34+
"""
35+
value = environ.get(config)
36+
if not value:
37+
raise ValueError(f"{config} is missing from .env.")
38+
return value
39+
40+
41+
GS_DATABASE_USER = getenv("GS_DATABASE_USER")
42+
GS_DATABASE_PASSWORD = getenv("GS_DATABASE_PASSWORD")
43+
GS_DATABASE_LOCATION = getenv("GS_DATABASE_LOCATION")
44+
GS_DATABASE_PORT = getenv("GS_DATABASE_PORT")
45+
GS_DATABASE_NAME = getenv("GS_DATABASE_NAME")
3146

3247
DATABASE_CONNECTION_STRING: Final[
3348
str

0 commit comments

Comments
 (0)