Initial commit

This commit is contained in:
ThePetrovich 2026-08-17 22:50:10 +08:00
commit 5cda7bc309
28 changed files with 1173 additions and 0 deletions

34
yksa_kit/settings.py Normal file
View file

@ -0,0 +1,34 @@
"""Settings helpers. Imported from a service's ``settings/base.py``."""
from __future__ import annotations
import os
_TRUE = {"1", "true", "yes", "on"}
def read_secret(secret_name: str, default: str | None = None) -> str | None:
"""Resolution order: docker secret, then fall back to environment, then to default.
"""
secret_path = f"/run/secrets/{secret_name}"
if os.path.exists(secret_path):
with open(secret_path, "r", encoding="utf-8") as file:
return file.read().strip()
return os.getenv(secret_name.upper(), default)
def env_bool(name: str, default: bool = False) -> bool:
"""Accepts 1/true/yes/on in any case.
Exists because ``os.getenv("X") == "True"`` silently ignored ``TRUE`` and
``1`` in two of the services' compose files.
"""
raw = os.getenv(name)
if raw is None:
return default
return raw.strip().lower() in _TRUE
def env_list(name: str, default: list[str] | None = None) -> list[str]:
raw = os.getenv(name, "")
return [item.strip() for item in raw.split(",") if item.strip()] or list(default or [])