add shortcut for admins in /stats

This commit is contained in:
Josh Hawkins 2026-05-13 10:33:42 -05:00
parent b2e16ee5de
commit b0caf5253d

View File

@ -101,6 +101,11 @@ def stats(
allowed_cameras: List[str] = Depends(get_allowed_cameras_for_filter), allowed_cameras: List[str] = Depends(get_allowed_cameras_for_filter),
): ):
stats_data = request.app.stats_emitter.get_latest_stats() stats_data = request.app.stats_emitter.get_latest_stats()
# Admins see the full snapshot
if request.headers.get("remote-role") == "admin":
return JSONResponse(content=stats_data)
allowed_set = set(allowed_cameras) allowed_set = set(allowed_cameras)
# Shallow-copy so we don't mutate the cached stats history entry. # Shallow-copy so we don't mutate the cached stats history entry.
@ -118,9 +123,8 @@ def stats(
name: data for name, data in bandwidth.items() if name in allowed_set name: data for name, data in bandwidth.items() if name in allowed_set
} }
# cmdline can leak camera URLs/paths; strip for non-admin but keep # cmdline can leak camera URLs/paths; strip but keep cpu/mem so
# cpu/mem so client-side problem heuristics still work. # client-side problem heuristics still work.
if request.headers.get("remote-role") != "admin":
cpu_usages = stats_data.get("cpu_usages") cpu_usages = stats_data.get("cpu_usages")
if cpu_usages is not None: if cpu_usages is not None:
filtered["cpu_usages"] = { filtered["cpu_usages"] = {