yksa-django-kit/yksa_kit/conf.py
2026-08-17 22:50:10 +08:00

29 lines
805 B
Python

"""The two settings every service must declare, and their fallbacks."""
from __future__ import annotations
from django.conf import settings
DEFAULT_SERVICE = "yksa"
def service() -> str:
"""Short service slug: ``tdas``, ``odms``, ``ops``.
Namespaces every cache key this package writes. The services share one Redis,
so a wrong or missing value silently merges two rate-limit budgets.
"""
return getattr(settings, "YKSA_SERVICE", DEFAULT_SERVICE)
def user_agent() -> str:
"""Identifies us to the upstreams we poll; several ban unattributed clients."""
return getattr(
settings,
"YKSA_USER_AGENT",
f"yksa-{service()}/0.1 (+https://{service()}.tmtc.yksa.space)",
)
def cache_key(*parts: str) -> str:
return ":".join((service(), *parts))