Add GET /api/v1/config (Phase 2)
Returns the device's settings document: the stored JSONB, plus the settings that live in real columns, plus config_version last - mirroring configApplyJson, which applies the version only after the rest of the payload has been processed. No response model, deliberately. devices.config is one JSONB document rather than forty columns because the firmware grows tunables faster than a schema should change, and the device merges and clamps whatever arrives: unknown keys ignored, absent keys left alone, dangerous values clamped on the device itself. Partial documents are the normal case, not a degraded one. Validating this shape belongs on the write path, when the admin UI saves a config. Unknown keys are passed through rather than filtered, so the admin UI can push a new firmware tunable without waiting for the server to learn it. Column-backed keys win over any stale copy of themselves in the JSONB. The columns are the modelled source of truth, and a leftover key shadowing one would mean a change to the column never reached the camera. This also closes a loop left open at enrollment. Enrollment refuses to let a device overwrite a rename made in the admin UI, which raised the fair question of how the rename ever reaches the device. It reaches it here: configApplyJson merges device_name like any other key (app_config.cpp:307). The operator owns the name, the server pushes it down, and the device adopts it - so the two decisions are consistent rather than merely defensible. Named device_config.py so it does not read as poorbird.config. The route is /config as specified. Tests: 99 -> 109. Verified by letting the JSONB win over the columns: the precedence test fails, as intended. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
5fd3c094a4
commit
e83fc757d0
3 files changed
+244
-3
No files matched your search
@@ -8,7 +8,7 @@ from fastapi import FastAPI
|
||||
from .. import __version__
|
||||
from ..config import get_settings
|
||||
from ..logging_setup import configure_logging
|
||||
from .routes import conditions, enroll, health
|
||||
from .routes import conditions, device_config, enroll, health
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -47,9 +47,9 @@ def create_app() -> FastAPI:
|
||||
# Phase 2 device endpoints. See firmware/API.md for the contract.
|
||||
app.include_router(enroll.router, prefix=API_PREFIX)
|
||||
app.include_router(conditions.router, prefix=API_PREFIX)
|
||||
app.include_router(device_config.router, prefix=API_PREFIX)
|
||||
|
||||
# Still to come: /ingest, /config, /commands/{id}/ack,
|
||||
# /firmware/{version}.bin.
|
||||
# Still to come: /ingest, /commands/{id}/ack, /firmware/{version}.bin.
|
||||
# Phase 3 mounts the UI endpoints.
|
||||
|
||||
return app
|
||||
|
||||
Reference in new issue
Block a user