This is an automated email from the ASF dual-hosted git repository.

bossenti pushed a commit to branch 1670-python-client-error-when-using-port-443
in repository https://gitbox.apache.org/repos/asf/streampipes.git


The following commit(s) were added to 
refs/heads/1670-python-client-error-when-using-port-443 by this push:
     new 7fd1a4e15 fix(#1670): validate client config and create proper error 
message
7fd1a4e15 is described below

commit 7fd1a4e159938b16d8c7a017dde76cf47f2aa416
Author: Tim Bossenmaier <[email protected]>
AuthorDate: Sun Oct 15 12:07:55 2023 +0200

    fix(#1670): validate client config and create proper error message
---
 streampipes-client-python/streampipes/client/client.py | 12 ++++++++++++
 streampipes-client-python/tests/client/test_client.py  | 12 ++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/streampipes-client-python/streampipes/client/client.py 
b/streampipes-client-python/streampipes/client/client.py
index 7d613d870..8cd1e6f1e 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,13 @@ class StreamPipesClient:
         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 a9c1ffc26..260ba35ee 100644
--- a/streampipes-client-python/tests/client/test_client.py
+++ b/streampipes-client-python/tests/client/test_client.py
@@ -79,6 +79,18 @@ class TestStreamPipesClient(TestCase):
         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):

Reply via email to