-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathenv_handler.py
40 lines (29 loc) · 863 Bytes
/
env_handler.py
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
32
33
34
35
36
37
38
39
40
import os
import sys
from dotenv import load_dotenv
from utils import logutil
logger = logutil.init_logger("process_embed.py")
load_dotenv()
def check_for_var(varname: str):
"""
Check if a variable is present in the environment
"""
if varname not in os.environ:
logger.critical(
f"{varname} not found. Please make sure it is present in your environment variables (.env file) before starting. Terminating process..."
)
sys.exit(1)
def load_var(varname: str):
"""
Load a variable from the environment
"""
logger.info(f"Loading environment variable {varname}...")
return str(os.environ.get(varname))
def validate_env() -> bool:
"""
Validate environment variables
"""
check_for_var("TOKEN")
check_for_var("GH_TOKEN")
check_for_var("DEV_GUILD")
return True