feat(camera): add generic REST/JSON snapshot camera adapter#382
Merged
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
URLCameracannot decode. Motivated by the vigilant.cat API (Bearertoken +{"data": "<base64 jpeg>"}), but generic enough to reuse for any similar REST/aggregator API without new code.What changes
RestSnapshotCamera(camera/adapters/rest.py):response=imageorjson; dot-path extraction;base64/nested-urldecoding; retries; sensitive headers and query params redacted in logs.registry.pyas adapter"rest"(alias"api");${VAR}placeholders in url/header values resolve from the environment, keeping tokens in.envrather than the mountedcredentials.json.urlmode, auth headers are only forwarded when the nested URL is same-origin, to avoid leaking tokens to a CDN/other host.docker-compose.ymlnow loads.envinto the camera API service so${VAR}tokens reach the container.Config example (vigilant.cat)
Validation
pytest tests/test_rest_snapshot.py— 10 passedruff check+ruff format --check(changed files) — cleanmypy(full project) — no issues in 45 filesdocker compose config— validNotes
pyro_camera_api/tests/and are not yet run by CI (tests.ymlonly runs the top-leveltests/). Wiringpyro_camera_apiinto CI is a suggested follow-up.credentials.jsonis committed.