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_url: str = remote.get("url", "").rstrip("/")
|
||||
remote_key: str = remote.get("key", "")
|
||||
key = remote_key
|
||||
auth_headers = {"Authorization": f"Bearer {key}"} if key else {}
|
||||
now = time.time()
|
||||
for device in state.get("devices", {}).values():
|
||||
viewing_session = device.get("viewing_session")
|
||||
@@ -242,9 +244,7 @@ async def _run_poll_cycle() -> None:
|
||||
try:
|
||||
await _federation_client.post(
|
||||
bell_clear_url,
|
||||
headers={"Authorization": f"Bearer {remote_key}"}
|
||||
if remote_key
|
||||
else {},
|
||||
headers=auth_headers,
|
||||
)
|
||||
except Exception as exc:
|
||||
_log.warning(
|
||||
@@ -1091,13 +1091,12 @@ async def federation_terminal_ws_proxy(websocket: WebSocket, device_id: str) ->
|
||||
|
||||
await websocket.accept(subprotocol="tty")
|
||||
|
||||
auth_headers = {"Authorization": f"Bearer {remote_key}"} if remote_key else {}
|
||||
try:
|
||||
async with websockets.connect(
|
||||
ws_url,
|
||||
subprotocols=[Subprotocol("tty")],
|
||||
additional_headers={"Authorization": f"Bearer {remote_key}"}
|
||||
if remote_key
|
||||
else {},
|
||||
additional_headers=auth_headers,
|
||||
ssl=ssl_context,
|
||||
) as remote_ws:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user