Skip to content

Commit 14aa770

Browse files
committed
added logging
1 parent 3f6505a commit 14aa770

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

databricks/sdk/credentials_provider.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ def inner(
117117
def wrapper(cfg: "Config") -> Optional[OAuthCredentialsProvider]:
118118
# Early environment detection - check before config validation
119119
if env_vars and not all(os.environ.get(var) for var in env_vars):
120+
# Provide specific error message for Azure DevOps OIDC SYSTEM_ACCESSTOKEN
121+
if name == "azdo-oidc" and "SYSTEM_ACCESSTOKEN" in env_vars and not os.environ.get("SYSTEM_ACCESSTOKEN"):
122+
logger.debug("Azure DevOps OIDC: SYSTEM_ACCESSTOKEN env var not found. If calling from Azure DevOps Pipeline, please set this env var following https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml#systemaccesstoken")
123+
else:
124+
logger.debug(f"{name}: required environment variables not present, skipping")
120125
return None
121126

122127
for attr in require:
@@ -447,8 +452,11 @@ def azure_devops_oidc(cfg: "Config") -> Optional[CredentialsProvider]:
447452
# Try to get an idToken. If no supplier returns a token, we cannot use this authentication mode.
448453
id_token = supplier.get_oidc_token(audience)
449454
if not id_token:
455+
logger.debug("Azure DevOps OIDC: no token available, skipping authentication method")
450456
return None
451457

458+
logger.info("Configured Azure DevOps OIDC authentication")
459+
452460
def token_source_for(audience: str) -> oauth.TokenSource:
453461
id_token = supplier.get_oidc_token(audience)
454462
if not id_token:

databricks/sdk/oidc_token_supplier.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import logging
12
import os
23
from typing import Optional
34

45
import requests
56

7+
logger = logging.getLogger("databricks.sdk")
8+
69

710
class GitHubOIDCTokenSupplier:
811
"""
@@ -50,6 +53,7 @@ def get_oidc_token(self, audience: str) -> Optional[str]:
5053
# Check for required variables
5154
if not all([access_token, collection_uri, project_id, plan_id, job_id, hub_name]):
5255
# not in Azure DevOps pipeline
56+
logger.debug("Azure DevOps OIDC: not in Azure DevOps pipeline environment")
5357
return None
5458

5559
try:
@@ -68,14 +72,17 @@ def get_oidc_token(self, audience: str) -> Optional[str]:
6872
# Azure DevOps OIDC endpoint requires POST request with empty body
6973
response = requests.post(endpoint, headers=headers)
7074
if not response.ok:
75+
logger.debug(f"Azure DevOps OIDC: token request failed with status {response.status_code}")
7176
return None
7277

7378
# Azure DevOps returns the token in 'oidcToken' field
7479
response_json = response.json()
7580
if "oidcToken" not in response_json:
81+
logger.debug("Azure DevOps OIDC: response missing 'oidcToken' field")
7682
return None
7783

84+
logger.debug("Azure DevOps OIDC: successfully obtained token")
7885
return response_json["oidcToken"]
79-
except Exception:
80-
# If any error occurs, return None to fall back to other auth methods
86+
except Exception as e:
87+
logger.debug(f"Azure DevOps OIDC: failed to get token: {e}")
8188
return None

0 commit comments

Comments
 (0)