From 857edb366487f6c78e19a00a995fc8d12c10e6ea Mon Sep 17 00:00:00 2001 From: Tim <50115603+bossenti@users.noreply.github.com> Date: Mon, 16 Oct 2023 09:32:30 +0200 Subject: [PATCH] fix(#1670): validate client config and create proper error message (#2026) --- .../streampipes/client/client.py | 14 ++++++++++++++ .../tests/client/test_client.py | 12 ++++++++++++ 2 files changed, 26 insertions(+) diff --git a/streampipes-client-python/streampipes/client/client.py b/streampipes-client-python/streampipes/client/client.py index 7d613d8704..047e52cc89 100644 --- a/streampipes-client-python/streampipes/client/client.py +++ b/streampipes-client-python/streampipes/client/client.py @@ -65,6 +65,11 @@ class StreamPipesClient: dataStreamApi: DataStreamEndpoint Instance of the data stream endpoint + Raises + ------ + AttributeError: + In case an invalid configuration of the `StreamPipesClientConfig` is passed + Examples -------- @@ -117,6 +122,15 @@ def __init__( client_config: StreamPipesClientConfig, logging_level: Optional[int] = logging.INFO, ): + # validate client config + # `https_disabled` and `port` 443 is an invalid configuration + if client_config.https_disabled and client_config.port == 443: + raise AttributeError( + "Invalid configuration passed! The given client configuration has " + "`https_disabled` set to `True` and `port` set to `443`.\n " + "If you want to connect to port 443, use `https_disabled=False` or " + "alternatively connect to port `80`." + ) self.client_config = client_config # set up a requests session diff --git a/streampipes-client-python/tests/client/test_client.py b/streampipes-client-python/tests/client/test_client.py index a9c1ffc265..260ba35ee4 100644 --- a/streampipes-client-python/tests/client/test_client.py +++ b/streampipes-client-python/tests/client/test_client.py @@ -79,6 +79,18 @@ def test_client_create(self, server_version: MagicMock): self.assertTrue(isinstance(result.dataLakeMeasureApi, DataLakeMeasureEndpoint)) self.assertEqual(result.base_api_path, "https://localhost:443/streampipes-backend/") + def test_client_create_invalid_config(self): + + with self.assertRaises(AttributeError): + StreamPipesClient.create( + client_config=StreamPipesClientConfig( + credential_provider=StreamPipesApiKeyCredentials(username="user", api_key="key"), + host_address="localhost", + https_disabled=True, + port=443, + ) + ) + @patch("streampipes.client.client.logger", autospec=True) @patch("streampipes.endpoint.endpoint.APIEndpoint._make_request", autospec=True) def test_client_describe(self, make_request: MagicMock, mocked_logger: MagicMock):