feat(python-client): send bearer token on WS upgrade#1400
Open
sridhar-3009 wants to merge 1 commit into
Open
Conversation
SensingClient had no credential path at all — grep for Authorization|RUVIEW_API_TOKEN across python/ returned nothing — so it cannot connect to a sensing-server with RUVIEW_API_TOKEN set. The TS MCP client has honoured this token for a while; this closes the gap for the Python client. Added a token param to SensingClient.__init__, defaulting to RUVIEW_API_TOKEN when not passed explicitly, sent as 'Authorization: Bearer <token>' on the WS upgrade when present. Python isn't browser-constrained like the web UI, so the header goes straight on the upgrade request — no ticket/round-trip indirection needed. Handled the websockets>=12.0 keyword-argument rename deliberately: the custom-headers kwarg to websockets.connect() is extra_headers below version 14 and additional_headers from 14 onward. Detected via inspect.signature() at import time rather than parsing __version__, so it can't be thrown off by a version string format change. Verified against 12.0, 13.1, and 16.1.1 directly (installed each in an isolated venv and inspected the real connect() signature) before writing the branch — a naive single-keyword implementation would work on whichever version happened to be installed and raise TypeError on the other side of the cutover. Tests cover: token sent as the correct header value, no token passed and RUVIEW_API_TOKEN unset means no Authorization header is sent at all (not an empty one), and the RUVIEW_API_TOKEN env fallback. All pass against both websockets 13.1 (extra_headers) and 16.1.1 (additional_headers) — ran the whole suite against each in isolated venvs to confirm the branch picks the right keyword on both sides of the rename. Fixes ruvnet#1395
|
Heads-up: #1400 and #1396 implement the same feature — bearer-token auth on the Both look sound. This one (#1400) fits the file's existing |
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.
Fixes #1395.
Problem
SensingClient(python/wifi_densepose/client/ws.py) had no credential path at all —git grep -n "Authorization\|RUVIEW_API_TOKEN" python/returned nothing. Against a sensing-server withRUVIEW_API_TOKENset, the Python client simply cannot connect. The TS MCP client (tools/ruview-mcp/src/http.ts) has honoured this token for a while, so this was a gap between the two clients rather than a missing feature overall.Fix
SensingClient.__init__accepts atokenkeyword, defaulting toRUVIEW_API_TOKENwhen not passed explicitly.__aenter__sendsAuthorization: Bearer <token>on the WS upgrade. Python isn't browser-constrained the way the web UI is, so this goes straight on the upgrade request — no ticket/round-trip indirection, per the issue's explicit guidance.websockets>=12.0keyword rename deliberately, per the issue's callout: the header kwarg towebsockets.connect()isextra_headersbelow version 14 andadditional_headersfrom 14 onward. Detected viainspect.signature(websockets.connect).parametersat import time, not by parsing__version__— so it can't be thrown off by a version-string format change on either side of the cutover.Testing
I didn't just trust the issue's description of the version split — I installed
websockets12.0, 13.1, and 16.1.1 in three isolated venvs and inspected the actualconnect()signature in each to confirm exactly whereextra_headersbecomesadditional_headersbefore writing the branch logic.Added three tests to
test_client_ws.pyusing the same in-processwebsockets.serve()pattern the file already uses:Authorization: Bearer <token>headerRUVIEW_API_TOKENunset → noAuthorizationheader sent at all (not an empty one)RUVIEW_API_TOKENenv var is honoured when no token is passed explicitlyRan the full
test_client_ws.pysuite (9 tests, including the 3 new ones) against bothwebsockets13.1 and 16.1.1 in separate venvs — all pass on both sides of the keyword rename. Also confirmed the change doesn't newly breakruff checkbeyond one pre-existing style debt already present in this file (Optional[X]vsX | None) that I matched rather than mixed styles.