36 lines
967 B
Python
36 lines
967 B
Python
"""Configuration loading from .env (CONFLUENCE_PAT, CONFLUENCE_URL)."""
|
|
import os
|
|
from pathlib import Path
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
|
ENV_FILE = BASE_DIR / ".env"
|
|
|
|
load_dotenv(ENV_FILE)
|
|
|
|
|
|
def get_pat() -> str:
|
|
"""Return the Confluence personal access token from CONFLUENCE_PAT."""
|
|
pat = os.getenv("CONFLUENCE_PAT", "").strip()
|
|
if not pat:
|
|
raise RuntimeError(
|
|
"CONFLUENCE_PAT is not set. Add it to .env (see .env.example)."
|
|
)
|
|
return pat
|
|
|
|
|
|
def get_url() -> str:
|
|
"""Return the Confluence base URL from CONFLUENCE_URL (no trailing slash)."""
|
|
url = os.getenv("CONFLUENCE_URL", "").strip().rstrip("/")
|
|
if not url:
|
|
raise RuntimeError(
|
|
"CONFLUENCE_URL is not set. Add it to .env (see .env.example)."
|
|
)
|
|
return url
|
|
|
|
|
|
def get_config() -> dict:
|
|
"""Return both settings as a dict."""
|
|
return {"url": get_url(), "pat": get_pat()}
|