Skip to content

feat(camera): add generic REST/JSON snapshot camera adapter#382

Merged
MateoLostanlen merged 6 commits into
developfrom
feat/rest-snapshot-adapter
Jul 11, 2026
Merged

feat(camera): add generic REST/JSON snapshot camera adapter#382
MateoLostanlen merged 6 commits into
developfrom
feat/rest-snapshot-adapter

Conversation

@MateoLostanlen

Copy link
Copy Markdown
Member

Adds a config-driven HTTP snapshot adapter for camera endpoints that need custom auth headers or return the image wrapped in JSON (base64 or a nested URL) — which the existing URLCamera cannot decode. Motivated by the vigilant.cat API (Bearer token + {"data": "<base64 jpeg>"}), but generic enough to reuse for any similar REST/aggregator API without new code.

What changes

  • New RestSnapshotCamera (camera/adapters/rest.py): response = image or json; dot-path extraction; base64/nested-url decoding; retries; sensitive headers and query params redacted in logs.
  • Wired into registry.py as adapter "rest" (alias "api"); ${VAR} placeholders in url/header values resolve from the environment, keeping tokens in .env rather than the mounted credentials.json.
  • Security: for nested-url mode, auth headers are only forwarded when the nested URL is same-origin, to avoid leaking tokens to a CDN/other host.
  • Deploy: docker-compose.yml now loads .env into the camera API service so ${VAR} tokens reach the container.

Config example (vigilant.cat)

"vigilant_can_mitjans": {
  "adapter": "rest", "type": "static",
  "url": "https://vigilant.cat/api/v1/cameras/<uuid>/snap",
  "headers": {"Authorization": "Bearer ${VIGILANT_TOKEN}"},
  "response": "json", "json_path": "data", "encoding": "base64"
}

Validation

  • pytest tests/test_rest_snapshot.py — 10 passed
  • ruff check + ruff format --check (changed files) — clean
  • mypy (full project) — no issues in 45 files
  • docker compose config — valid

Notes

  • The new tests live under pyro_camera_api/tests/ and are not yet run by CI (tests.yml only runs the top-level tests/). Wiring pyro_camera_api into CI is a suggested follow-up.
  • No token, camera UUID, or credentials.json is committed.

HTTP snapshot adapter for endpoints that need custom auth headers or return
the image wrapped in JSON (base64 or nested URL), which URLCamera cannot
handle. Configurable response mode, dot-path extraction, retries; sensitive
headers and query params redacted in logs.
Register 'rest'/'api' adapters from config and resolve ${VAR} placeholders in
url/header values from the environment, so tokens live in .env instead of the
mounted credentials.json. Unset variables fail the camera fast at registration.
Raw image, JSON+base64 (vigilant.cat shape), data-URI stripping, nested-URL
re-fetch, HTTP error, retry-then-success, give-up, and log redaction.
For encoding='url' the JSON endpoint controls the nested URL. Only reuse the
configured auth headers when it stays same-origin; strip sensitive headers
otherwise so a bearer token/API key is not disclosed to another host.
The pyro-camera-api service only passed a fixed env allowlist, so ${VAR}
tokens referenced by rest cameras were absent in the container and failed
registration. Load .env so they resolve.
@codecov

codecov Bot commented Jul 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.83%. Comparing base (a227753) to head (17419b6).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop     #382   +/-   ##
========================================
  Coverage    78.83%   78.83%           
========================================
  Files            6        6           
  Lines          841      841           
========================================
  Hits           663      663           
  Misses         178      178           
Flag Coverage Δ
unittests 78.83% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@MateoLostanlen MateoLostanlen merged commit b153ce5 into develop Jul 11, 2026
11 checks passed
@MateoLostanlen MateoLostanlen deleted the feat/rest-snapshot-adapter branch July 11, 2026 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant