- integer-id persistence: memory (default, zero-dep) + mongo_int repos
selected by REPO_BACKEND via create_repo factory
- interfaces/_common.py: shared svc/dump/paginate/expand_ref/read_or_404
helpers; item/job routes rebuilt on them (paginated {total,items} lists,
PUT replace, 204 deletes, int path ids)
- interfaces/system: /health liveness probe (public)
- openapi.yaml rewritten to 3.1.0 with x- extensions on Item/Job
(x-resource, x-primary-key, x-display-format, x-list-columns, x-label,
x-order, x-hidden, x-filterable, x-sortable, x-autocomplete), auth-server
x-* securityScheme wiring, shared error responses
- config/init/main: REPO_BACKEND knob, load_dotenv before spec build
Verified: 7/7 tests pass; live smoke test (/health ok, 401 without token)
61 lines
2.3 KiB
Python
61 lines
2.3 KiB
Python
"""# Summary
|
|
|
|
App configuration loaded from environment — a Settings dataclass with defaults
|
|
plus a singleton settings instance populated from OS environment variables at
|
|
import time.
|
|
|
|
---
|
|
|
|
The template reads these knobs:
|
|
|
|
- ``repo_backend`` — ``memory`` (default, zero-dependency process-local store)
|
|
or ``mongo`` (persistent, via the shared mongo-ops connection manager).
|
|
- ``mongo_uri`` / ``mongo_db`` — connection targets when the Mongo backend is
|
|
selected.
|
|
- ``port`` — the port uvicorn binds (keep in sync with the OpenAPI
|
|
``servers:`` entry and the client's ``VITE_API_BASE_URL``).
|
|
- ``worker_poll_seconds`` / ``worker_max_retries`` — background worker cadence.
|
|
|
|
``AUTH_SERVER`` is intentionally *not* re-exported here: ``openapi_first``
|
|
resolves ``{AUTH_SERVER}`` straight from the process environment when the
|
|
application is built, so the env var remains the single source of truth for
|
|
the generated bearer-JWT introspection dependency.
|
|
"""
|
|
import os
|
|
from dataclasses import dataclass
|
|
|
|
|
|
@dataclass
|
|
class Settings:
|
|
"""Runtime configuration settings for the application.
|
|
|
|
Attributes:
|
|
debug (bool): Enable debug behavior. Defaults to False.
|
|
repo_backend (str): Persistence flavour, ``memory`` or ``mongo``.
|
|
Defaults to ``memory``.
|
|
mongo_uri (str): MongoDB connection URI. Defaults to mongodb://localhost:27017.
|
|
mongo_db (str): MongoDB database name. Defaults to app_template.
|
|
port (int): Local HTTP port. Defaults to 8000.
|
|
worker_poll_seconds (int): Worker poll interval in seconds. Defaults to 30.
|
|
worker_max_retries (int): Maximum job retries before skipping. Defaults to 3.
|
|
"""
|
|
|
|
debug: bool = False
|
|
repo_backend: str = "memory"
|
|
mongo_uri: str = "mongodb://localhost:27017"
|
|
mongo_db: str = "app_template"
|
|
port: int = 8000
|
|
worker_poll_seconds: int = 30
|
|
worker_max_retries: int = 3
|
|
|
|
|
|
settings = Settings(
|
|
debug=os.environ.get("DEBUG", "").lower() in ("1", "true", "yes"),
|
|
repo_backend=os.environ.get("REPO_BACKEND", "memory").lower(),
|
|
mongo_uri=os.environ.get("MONGO_URI", "mongodb://localhost:27017"),
|
|
mongo_db=os.environ.get("MONGO_DB", "app_template"),
|
|
port=int(os.environ.get("PORT", "8000")),
|
|
worker_poll_seconds=int(os.environ.get("WORKER_POLL_SECONDS", "30")),
|
|
worker_max_retries=int(os.environ.get("WORKER_MAX_RETRIES", "3")),
|
|
)
|