Increase platform abstraction cohesion

This commit is contained in:
2026-03-06 17:47:58 +00:00
parent 438e561da0
commit 8c091b1e6d
55 changed files with 6555 additions and 440 deletions

View File

@@ -1,16 +1,39 @@
from os import getenv
from urllib.parse import urlparse
trues = ("t", "true", "yes", "y", "1")
def _csv_env(name: str, default: str) -> list[str]:
return [item.strip() for item in getenv(name, default).split(",") if item.strip()]
# URLs
DOMAIN = getenv("DOMAIN", "example.com")
URL = getenv("URL", f"https://{DOMAIN}")
URL_HOST = urlparse(URL).hostname or ""
DEBUG = getenv("DEBUG", "false").lower() in trues
# Access control
ALLOWED_HOSTS = getenv("ALLOWED_HOSTS", f"localhost,{DOMAIN}").split(",")
ALLOWED_HOSTS = _csv_env(
"ALLOWED_HOSTS",
",".join(
item
for item in (
"localhost",
"127.0.0.1",
DOMAIN,
URL_HOST,
)
if item
),
)
if DEBUG:
# Local/dev stack runs behind varying hostnames/tunnels.
ALLOWED_HOSTS = ["*"]
# CSRF
CSRF_TRUSTED_ORIGINS = getenv("CSRF_TRUSTED_ORIGINS", URL).split(",")
CSRF_TRUSTED_ORIGINS = _csv_env("CSRF_TRUSTED_ORIGINS", URL)
# Stripe
BILLING_ENABLED = getenv("BILLING_ENABLED", "false").lower() in trues
@@ -23,7 +46,10 @@ STRIPE_PUBLIC_API_KEY_PROD = getenv("STRIPE_PUBLIC_API_KEY_PROD", "")
STRIPE_ENDPOINT_SECRET = getenv("STRIPE_ENDPOINT_SECRET", "")
STATIC_ROOT = getenv("STATIC_ROOT", "")
SECRET_KEY = getenv("SECRET_KEY", "")
SECRET_KEY = (getenv("SECRET_KEY", "") or "").strip()
if not SECRET_KEY:
# Keep local developer stacks usable when stack.env is uninitialized.
SECRET_KEY = "gia-dev-secret-key"
STRIPE_ADMIN_COUPON = getenv("STRIPE_ADMIN_COUPON", "")
@@ -33,7 +59,6 @@ LAGO_API_KEY = getenv("LAGO_API_KEY", "")
LAGO_ORG_ID = getenv("LAGO_ORG_ID", "")
LAGO_URL = getenv("LAGO_URL", "")
DEBUG = getenv("DEBUG", "false") in trues
PROFILER = getenv("PROFILER", "false") in trues
if DEBUG:
@@ -62,7 +87,8 @@ INSTAGRAM_HTTP_URL = getenv("INSTAGRAM_HTTP_URL", "http://instagram:8080")
XMPP_ADDRESS = getenv("XMPP_ADDRESS")
XMPP_JID = getenv("XMPP_JID")
XMPP_PORT = getenv("XMPP_PORT")
XMPP_USER_DOMAIN = getenv("XMPP_USER_DOMAIN", "")
XMPP_PORT = int(getenv("XMPP_PORT", "8888") or 8888)
XMPP_SECRET = getenv("XMPP_SECRET")
EVENT_LEDGER_DUAL_WRITE = getenv("EVENT_LEDGER_DUAL_WRITE", "false").lower() in trues