Skip to content

Commit

Permalink
connection string no authentication option + (local) test (#509)
Browse files Browse the repository at this point in the history
* connection string no authentication option + (local) test

* fixed psf

* Added device login flag and changed deafult to interactive login
  • Loading branch information
t-ronmoneta authored Nov 26, 2023
1 parent 57a8f57 commit 7cc9023
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
15 changes: 15 additions & 0 deletions azure-kusto-data/azure/kusto/data/kcsb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -482,6 +484,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://<clusterName>.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.
Expand Down
4 changes: 3 additions & 1 deletion azure-kusto-data/azure/kusto/data/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
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."""
Expand Down Expand Up @@ -326,6 +329,12 @@ async def async_token_provider():
finally:
assert exception_occurred

@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"
Expand Down

0 comments on commit 7cc9023

Please sign in to comment.