From e97aab4f364c6c8089538969e5def69100aef20a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mose=20M=C3=BCller?= Date: Thu, 22 May 2025 16:07:52 +0200 Subject: [PATCH 1/3] client: adds hostname of the client as client_id default --- src/pydase/client/client.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pydase/client/client.py b/src/pydase/client/client.py index bbe21f1..2579b7b 100644 --- a/src/pydase/client/client.py +++ b/src/pydase/client/client.py @@ -1,5 +1,6 @@ import asyncio import logging +import socket import sys import threading import urllib.parse @@ -59,7 +60,8 @@ class Client: client's behaviour (e.g., reconnection attempts or reconnection delay). client_id: An optional client identifier. This ID is sent to the server as the `X-Client-Id` HTTP header. It can be used for logging or authentication - purposes on the server side. + purposes on the server side. If not provided, it defaults to the hostname + of the machine running the client. proxy_url: An optional proxy URL to route the connection through. This is useful if the service is only reachable via an SSH tunnel or behind a firewall (e.g., `socks5://localhost:2222`). @@ -112,7 +114,7 @@ class Client: self._path_prefix = parsed_url.path.rstrip("/") # Remove trailing slash if any self._url = url self._proxy_url = proxy_url - self._client_id = client_id + self._client_id = client_id or socket.gethostname() self._sio_client_kwargs = sio_client_kwargs self._loop: asyncio.AbstractEventLoop | None = None self._thread: threading.Thread | None = None From f48f7aacfbfbe99bd1144cb1d86ea157739f9fa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mose=20M=C3=BCller?= Date: Thu, 22 May 2025 16:10:22 +0200 Subject: [PATCH 2/3] docs: updates client_id description --- docs/user-guide/interaction/Python-Client.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/user-guide/interaction/Python-Client.md b/docs/user-guide/interaction/Python-Client.md index 2ac5190..1e910cb 100644 --- a/docs/user-guide/interaction/Python-Client.md +++ b/docs/user-guide/interaction/Python-Client.md @@ -58,7 +58,7 @@ class MyService(pydase.DataService): proxy = pydase.Client( url="ws://:", block_until_connected=False, - client_id="my_pydase_client_id", + client_id="my_pydase_client_id", # optional, defaults to system hostname ).proxy # For SSL-encrypted services, use the wss protocol @@ -77,7 +77,7 @@ if __name__ == "__main__": In this example: - The `MyService` class has a `proxy` attribute that connects to a `pydase` service at `:`. - By setting `block_until_connected=False`, the service can start without waiting for the connection to succeed. -- By setting `client_id`, the server will log a descriptive identifier for this client via the `X-Client-Id` HTTP header. +- The `client_id` is optional. If not specified, it defaults to the system hostname, which will be sent in the `X-Client-Id` HTTP header for logging or authentication on the server side. ## Custom `socketio.AsyncClient` Connection Parameters From e54710cd4db2f57604ee135f0469eb48a937e8c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mose=20M=C3=BCller?= Date: Thu, 22 May 2025 16:12:38 +0200 Subject: [PATCH 3/3] tests: update client_id test --- tests/client/test_client.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/client/test_client.py b/tests/client/test_client.py index c9acff4..eff1bd3 100644 --- a/tests/client/test_client.py +++ b/tests/client/test_client.py @@ -168,9 +168,11 @@ def test_context_manager(pydase_client: pydase.Client) -> None: def test_client_id( pydase_client: pydase.Client, caplog: pytest.LogCaptureFixture ) -> None: + import socket + pydase.Client(url="ws://localhost:9999") - assert "Client [sid=" in caplog.text + assert f"Client [id={socket.gethostname()}]" in caplog.text caplog.clear() pydase.Client(url="ws://localhost:9999", client_id="my_service")