Gateway: /api/v1 routes with bearer auth #7
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
Gateway service (see #18). The authenticated API the beets plugin consumes.
Task
app/routes.pywith a bearer-auth dependency (compare withhmac.compare_digestagainstSERVICE_TOKEN):GET /api/v1/status->{"logged_in": bool, "updated_at": str | null}GET /api/v1/playlists->[{"id", "name"}]GET /api/v1/playlists/{id}/tracks->[{"title", "artist", "album", "isrc", "track_number"}](serialize the
AppleTrackdataclasses;isrc/track_numbermay be null)DELETE /api/v1/login-> clears the token, 204/200GET /healthz-> 200 (already in the app factory)Behaviour: if Apple returns 401/403 for the stored user token (revoked or
expired), the API returns 502 with a message telling the user to visit
/loginagain. Unauthenticated/api/v1requests return 401 with a hintto visit
{GATEWAY_BASE_URL}/login.Acceptance criteria
reflects the store; playlists/tracks proxy the mocked Apple client;
DELETE /api/v1/loginclears; Apple 401 -> 502 with the re-login hint.Done in
coop/apple-music-gateway(commit6b45aa5):app/routes.pygains the authenticated API — a bearer dependency compares againstSERVICE_TOKENwithhmac.compare_digest(401 + login hint otherwise),GET /api/v1/statusreports{logged_in, updated_at}from the credential store,GET /api/v1/playlistsreturns[{id, name}],GET /api/v1/playlists/{id}/tracksserializesAppleTrackas{title, artist, album, isrc, track_number}(nulls allowed),DELETE /api/v1/loginclears the token. Apple 401/403 -> 502 with the re-login hint; no stored token -> 502 pointing at/login.CredentialStoregainedupdated_at()for the status route; the app factory exposesapp.state.apple_sessionso tests inject a FakeSession.tests/test_api_routes.pycovers 401s, status, proxying, logout, and the 502 hints; live smoke test of the running gateway confirmed all of it.uv run pytest: 62 passed.