-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.py
More file actions
31 lines (23 loc) · 949 Bytes
/
Copy pathsettings.py
File metadata and controls
31 lines (23 loc) · 949 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import os
from typing import Literal
from dotenv import dotenv_values, load_dotenv
IS_PROD: bool = False
MONGODB_URI: str = ""
BACKEND_MODE: Literal["db"] | Literal["local"] = "local"
def _get_config(key: str, env_file: str) -> str:
val = os.getenv(key)
if val is None or val == "":
raise ValueError(f"No environment variable found for {key} in {env_file}")
return val
def _make_config():
global IS_PROD, MONGODB_URI, BACKEND_MODE
IS_PROD = os.getenv("TODO_PRODUCTION") is not None
env_file = ".env.prod" if IS_PROD else ".env.dev"
env_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), env_file)
load_dotenv(env_file)
MONGODB_URI = _get_config("MONGODB_URI", env_file)
be_mode = _get_config("BACKEND_MODE", env_file)
if be_mode != "db" and be_mode != "local":
raise ValueError(f'BACKEND_MODE must be one of "db" | "local"')
BACKEND_MODE = be_mode
_make_config()