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"