From 14d6d6d8e3fb4304939379f6477cfec4f08df8b6 Mon Sep 17 00:00:00 2001 From: t-ronmoneta Date: Tue, 14 Nov 2023 14:43:11 +0200 Subject: [PATCH 1/3] connection string no authentication option + (local) test --- azure-kusto-data/azure/kusto/data/kcsb.py | 13 +++++++++++++ .../tests/test_kusto_connection_string_builder.py | 10 ++++++++++ 2 files changed, 23 insertions(+) diff --git a/azure-kusto-data/azure/kusto/data/kcsb.py b/azure-kusto-data/azure/kusto/data/kcsb.py index 903afc2a..d8a51475 100644 --- a/azure-kusto-data/azure/kusto/data/kcsb.py +++ b/azure-kusto-data/azure/kusto/data/kcsb.py @@ -482,6 +482,19 @@ def with_azure_token_credential( return kcsb + @classmethod + def with_no_authentication(cls, connection_string: str) -> "KustoConnectionStringBuilder": + """ + Create a KustoConnectionStringBuilder that uses no authentication. + :param connection_string: Kusto's connection string should be of the format: http://.kusto.windows.net + """ + if not connection_string.startswith("http://"): + raise ValueError("Connection string must start with http://") + kcsb = cls(connection_string) + kcsb[kcsb.ValidKeywords.aad_federated_security] = False + + return kcsb + @property def data_source(self) -> Optional[str]: """The URI specifying the Kusto service endpoint. diff --git a/azure-kusto-data/tests/test_kusto_connection_string_builder.py b/azure-kusto-data/tests/test_kusto_connection_string_builder.py index c65eba82..ced16ae8 100644 --- a/azure-kusto-data/tests/test_kusto_connection_string_builder.py +++ b/azure-kusto-data/tests/test_kusto_connection_string_builder.py @@ -3,8 +3,10 @@ import unittest from uuid import uuid4 +import pytest from azure.kusto.data import KustoConnectionStringBuilder, KustoClient +local_emulator = False class KustoConnectionStringBuilderTests(unittest.TestCase): """Tests class for KustoConnectionStringBuilder.""" @@ -326,6 +328,14 @@ async def async_token_provider(): finally: assert exception_occurred + @pytest.mark.skipif(not local_emulator, reason="requires aio") + def test_no_authentication(self): + kscb = KustoConnectionStringBuilder.with_no_authentication("http://localhost:8080") + assert kscb.data_source == "http://localhost:8080" + assert kscb.aad_federated_security is False + + + def test_initial_catalog_default(self): kcsb = KustoConnectionStringBuilder.with_az_cli_authentication("https://help.kusto.windows.net") assert kcsb.data_source == "https://help.kusto.windows.net" From b02fec312ffada57cb966c31c64ef592b8819061 Mon Sep 17 00:00:00 2001 From: t-ronmoneta Date: Wed, 15 Nov 2023 15:56:41 +0200 Subject: [PATCH 2/3] fixed psf --- .../tests/test_kusto_connection_string_builder.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/azure-kusto-data/tests/test_kusto_connection_string_builder.py b/azure-kusto-data/tests/test_kusto_connection_string_builder.py index ced16ae8..afa5a2a6 100644 --- a/azure-kusto-data/tests/test_kusto_connection_string_builder.py +++ b/azure-kusto-data/tests/test_kusto_connection_string_builder.py @@ -8,6 +8,7 @@ local_emulator = False + class KustoConnectionStringBuilderTests(unittest.TestCase): """Tests class for KustoConnectionStringBuilder.""" @@ -328,14 +329,12 @@ async def async_token_provider(): finally: assert exception_occurred - @pytest.mark.skipif(not local_emulator, reason="requires aio") + @pytest.mark.skipif(not local_emulator, reason="requires local emulator") def test_no_authentication(self): kscb = KustoConnectionStringBuilder.with_no_authentication("http://localhost:8080") assert kscb.data_source == "http://localhost:8080" assert kscb.aad_federated_security is False - - def test_initial_catalog_default(self): kcsb = KustoConnectionStringBuilder.with_az_cli_authentication("https://help.kusto.windows.net") assert kcsb.data_source == "https://help.kusto.windows.net" From 1af1d0aa6b20de6ab92bfd05039d412e66b85534 Mon Sep 17 00:00:00 2001 From: t-ronmoneta Date: Sun, 26 Nov 2023 14:50:12 +0200 Subject: [PATCH 3/3] Added device login flag and changed deafult to interactive login --- azure-kusto-data/azure/kusto/data/kcsb.py | 2 ++ azure-kusto-data/azure/kusto/data/security.py | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/azure-kusto-data/azure/kusto/data/kcsb.py b/azure-kusto-data/azure/kusto/data/kcsb.py index d8a51475..f0862ffe 100644 --- a/azure-kusto-data/azure/kusto/data/kcsb.py +++ b/azure-kusto-data/azure/kusto/data/kcsb.py @@ -132,6 +132,7 @@ def __init__(self, connection_string: str): self._token_provider = None self._async_token_provider = None self.is_token_credential_auth = False + self.is_device_login_auth = False self.credential: Optional[Any] = None self.credential_from_login_endpoint: Optional[Any] = None if connection_string is not None and "=" not in connection_string.partition(";")[0]: @@ -339,6 +340,7 @@ def with_aad_device_authentication( - ``expires_on`` (datetime.datetime) the UTC time at which the code will expire """ kcsb = cls(connection_string) + kcsb.is_device_login_auth = True kcsb[kcsb.ValidKeywords.aad_federated_security] = True kcsb[kcsb.ValidKeywords.authority_id] = authority_id kcsb.device_callback = callback diff --git a/azure-kusto-data/azure/kusto/data/security.py b/azure-kusto-data/azure/kusto/data/security.py index b9ff66ac..56b82507 100644 --- a/azure-kusto-data/azure/kusto/data/security.py +++ b/azure-kusto-data/azure/kusto/data/security.py @@ -72,8 +72,10 @@ def __init__(self, kcsb: "KustoConnectionStringBuilder", is_async: bool): credential=kcsb.credential, credential_from_login_endpoint=kcsb.credential_from_login_endpoint, ) - else: # TODO - next breaking change - remove this as default, make no auth the default + elif kcsb.is_device_login_auth: self.token_provider = DeviceLoginTokenProvider(self.kusto_uri, kcsb.authority_id, kcsb.device_callback, is_async=is_async) + else: + self.token_provider = InteractiveLoginTokenProvider(self.kusto_uri, kcsb.authority_id, kcsb.login_hint, kcsb.domain_hint, is_async=is_async) def acquire_authorization_header(self): try: