fix: extract auth_headers to local var to prevent ruff splitting inline guards
Ruff was reformatting the ternary header constructions to multi-line form:
headers={"Authorization": f"Bearer {remote_key}"}\n if remote_key\n else {},
This caused test_federation_auth_headers_guard_empty_key to fail because
the source-inspection test requires 'if' to appear on the same line as
the Authorization header dict.
Fix: assign to a local variable before use so ruff has no reason to split:
auth_headers = {"Authorization": f"Bearer {key}"} if key else {}
Applied at two sites:
- poll-cycle bell-clear (line ~232)
- federation WS proxy endpoint (line ~1094)
This commit is contained in:
+5
-6
@@ -228,6 +228,8 @@ async def _run_poll_cycle() -> None:
|
|||||||
remote = remote_instances[active_remote_id]
|
remote = remote_instances[active_remote_id]
|
||||||
remote_url: str = remote.get("url", "").rstrip("/")
|
remote_url: str = remote.get("url", "").rstrip("/")
|
||||||
remote_key: str = remote.get("key", "")
|
remote_key: str = remote.get("key", "")
|
||||||
|
key = remote_key
|
||||||
|
auth_headers = {"Authorization": f"Bearer {key}"} if key else {}
|
||||||
now = time.time()
|
now = time.time()
|
||||||
for device in state.get("devices", {}).values():
|
for device in state.get("devices", {}).values():
|
||||||
viewing_session = device.get("viewing_session")
|
viewing_session = device.get("viewing_session")
|
||||||
@@ -242,9 +244,7 @@ async def _run_poll_cycle() -> None:
|
|||||||
try:
|
try:
|
||||||
await _federation_client.post(
|
await _federation_client.post(
|
||||||
bell_clear_url,
|
bell_clear_url,
|
||||||
headers={"Authorization": f"Bearer {remote_key}"}
|
headers=auth_headers,
|
||||||
if remote_key
|
|
||||||
else {},
|
|
||||||
)
|
)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
_log.warning(
|
_log.warning(
|
||||||
@@ -1091,13 +1091,12 @@ async def federation_terminal_ws_proxy(websocket: WebSocket, device_id: str) ->
|
|||||||
|
|
||||||
await websocket.accept(subprotocol="tty")
|
await websocket.accept(subprotocol="tty")
|
||||||
|
|
||||||
|
auth_headers = {"Authorization": f"Bearer {remote_key}"} if remote_key else {}
|
||||||
try:
|
try:
|
||||||
async with websockets.connect(
|
async with websockets.connect(
|
||||||
ws_url,
|
ws_url,
|
||||||
subprotocols=[Subprotocol("tty")],
|
subprotocols=[Subprotocol("tty")],
|
||||||
additional_headers={"Authorization": f"Bearer {remote_key}"}
|
additional_headers=auth_headers,
|
||||||
if remote_key
|
|
||||||
else {},
|
|
||||||
ssl=ssl_context,
|
ssl=ssl_context,
|
||||||
) as remote_ws:
|
) as remote_ws:
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user