-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconstants.py
More file actions
51 lines (36 loc) · 1.36 KB
/
Copy pathconstants.py
File metadata and controls
51 lines (36 loc) · 1.36 KB
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
41
42
43
44
45
46
47
48
49
50
51
import logging
import os
from pathlib import Path
from sample.utils.config import load_env
load_env()
# These should be in environment variables or .env file.
DEFAULT_PORT = 8005
DEFAULT_API_PREFIX = "/api/v1"
DEFAULT_MONGODB_URI = (
"mongodb://127.0.0.1:27017/?retryWrites=true&w=majority&appName=Sample"
)
DEFAULT_DATABASE_NAME = "sample_db"
GREETING = "Hello"
# --- Asset paths ---
PROJECT_ROOT = Path(__file__).parent.parent
ASSETS_DIR = PROJECT_ROOT / "assets" / "images"
COMPANY_LOGO = ASSETS_DIR / "logo.png"
def safe_get(env_key: str, default) -> str:
value = os.getenv(env_key, default)
if not value:
raise RuntimeError(f"Missing required environment variable: {env_key}")
logging.info(f"Loaded config '{env_key}' from [env]")
return value
PORT = safe_get("PORT", DEFAULT_PORT)
PORT_API = safe_get("PORT_API", int(PORT) + 1)
API_PREFIX = safe_get("API_PREFIX", DEFAULT_API_PREFIX)
def get_mongo_config():
return {
"MONGODB_URI": safe_get("MONGODB_URI", DEFAULT_MONGODB_URI),
"DATABASE_NAME": safe_get("DATABASE_NAME", DEFAULT_DATABASE_NAME),
}
MONGO_CONFIG = get_mongo_config()
# === Environment Selection ===
ENVIRONMENT = safe_get("ENVIRONMENT", "development").lower()
logging.info(f"Environment: {ENVIRONMENT}", extra={"color": "yellow"})
logging.info(f"Project root: {PROJECT_ROOT}", extra={"color": "yellow"})