Skip to content

Commit f29ad4a

Browse files
authored
Reduce redundant warning messages in azure-cli credential provider (#410)
## Changes This warning is a bit noisy: in the happy path, we print it multiple times, and even if we don't use Azure CLI auth, we may print it anyways. Also, it will be printed always when using account-level authentication. This PR reduces the noise for this warning by only printing it when we are certainly going to use Azure CLI auth, authenticating to a workspace, and can't get the subscription ID (e.g. because it is not configured). ## Tests <!-- How is this tested? Please see the checklist below and also describe any other relevant tests --> - [x] Ran locally: with accounts client, no warning is printed, and with workspace client, only one warning is printed.
1 parent d4c160f commit f29ad4a

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

databricks/sdk/core.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ def __init__(self, resource: str, subscription: str = ""):
316316

317317
@staticmethod
318318
def for_resource(cfg: 'Config', resource: str) -> 'AzureCliTokenSource':
319-
subscription = AzureCliTokenSource._get_subscription(cfg)
319+
subscription = AzureCliTokenSource.get_subscription(cfg)
320320
if subscription != "":
321321
token = AzureCliTokenSource(resource, subscription)
322322
try:
@@ -327,19 +327,15 @@ def for_resource(cfg: 'Config', resource: str) -> 'AzureCliTokenSource':
327327
return token
328328
except OSError:
329329
logger.warning("Failed to get token for subscription. Using resource only token.")
330-
else:
331-
logger.warning(
332-
"azure_workspace_resource_id field not provided. " +
333-
"It is recommended to specify this field in the Databricks configuration to avoid authentication errors."
334-
)
330+
335331
token = AzureCliTokenSource(resource)
336332
token.token()
337333
return token
338334

339335
@staticmethod
340-
def _get_subscription(cfg: 'Config') -> str:
336+
def get_subscription(cfg: 'Config') -> str:
341337
resource = cfg.azure_workspace_resource_id
342-
if resource == None or resource == "":
338+
if resource is None or resource == "":
343339
return ""
344340
components = resource.split('/')
345341
if len(components) < 3:
@@ -368,6 +364,11 @@ def azure_cli(cfg: 'Config') -> Optional[HeaderFactory]:
368364

369365
_ensure_host_present(cfg, lambda resource: AzureCliTokenSource.for_resource(cfg, resource))
370366
logger.info("Using Azure CLI authentication with AAD tokens")
367+
if not cfg.is_account_client and AzureCliTokenSource.get_subscription(cfg) == "":
368+
logger.warning(
369+
"azure_workspace_resource_id field not provided. "
370+
"It is recommended to specify this field in the Databricks configuration to avoid authentication errors."
371+
)
371372

372373
def inner() -> Dict[str, str]:
373374
token = token_source.token()

0 commit comments

Comments
 (0)