This is an automated email from the ASF dual-hosted git repository.
bossenti pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/streampipes.git
The following commit(s) were added to refs/heads/dev by this push:
new 857edb366 fix(#1670): validate client config and create proper error
message (#2026)
857edb366 is described below
commit 857edb366487f6c78e19a00a995fc8d12c10e6ea
Author: Tim <[email protected]>
AuthorDate: Mon Oct 16 09:32:30 2023 +0200
fix(#1670): validate client config and create proper error message (#2026)
---
streampipes-client-python/streampipes/client/client.py | 14 ++++++++++++++
streampipes-client-python/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 7d613d870..047e52cc8 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 @@ 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):