Spaces:
Sleeping
Sleeping
File size: 855 Bytes
c1b1f3a | 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 | """Configuration for local development and hosted deployments."""
import os
from pathlib import Path
from typing import Optional
from dotenv import load_dotenv
_PROJECT_ROOT = Path(__file__).resolve().parents[1]
_LOCAL_ENV_FILES = (_PROJECT_ROOT / ".env", _PROJECT_ROOT.parent / ".env")
def load_local_environment() -> None:
"""Load ignored local dotenv files without overriding environment variables."""
for env_file in _LOCAL_ENV_FILES:
if env_file.is_file():
load_dotenv(env_file, override=False)
def get_secret(*names: str, default: Optional[str] = None) -> Optional[str]:
"""Return the first configured secret, normalized and never logged."""
load_local_environment()
for name in names:
value = os.getenv(name)
if value:
return value.strip().strip("'\"")
return default
|