Skip to content

Commit eabfc73

Browse files
committed
added environment variables to config
1 parent ef7a058 commit eabfc73

File tree

3 files changed

+34
-11
lines changed

3 files changed

+34
-11
lines changed

databricks/sdk/config.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ class Config:
8888
azure_client_id: str = ConfigAttribute(env="ARM_CLIENT_ID", auth="azure")
8989
azure_tenant_id: str = ConfigAttribute(env="ARM_TENANT_ID", auth="azure")
9090
azure_environment: str = ConfigAttribute(env="ARM_ENVIRONMENT")
91+
92+
# Azure DevOps environment variables (automatically provided by Azure DevOps pipelines)
93+
azure_devops_access_token: str = ConfigAttribute(env="SYSTEM_ACCESSTOKEN", auth="azdo-oidc", sensitive=True)
94+
azure_devops_collection_uri: str = ConfigAttribute(env="SYSTEM_TEAMFOUNDATIONCOLLECTIONURI", auth="azdo-oidc")
95+
azure_devops_project_id: str = ConfigAttribute(env="SYSTEM_TEAMPROJECTID", auth="azdo-oidc")
96+
azure_devops_plan_id: str = ConfigAttribute(env="SYSTEM_PLANID", auth="azdo-oidc")
97+
azure_devops_job_id: str = ConfigAttribute(env="SYSTEM_JOBID", auth="azdo-oidc")
98+
azure_devops_host_type: str = ConfigAttribute(env="SYSTEM_HOSTTYPE", auth="azdo-oidc")
99+
91100
databricks_cli_path: str = ConfigAttribute(env="DATABRICKS_CLI_PATH")
92101
auth_type: str = ConfigAttribute(env="DATABRICKS_AUTH_TYPE")
93102
cluster_id: str = ConfigAttribute(env="DATABRICKS_CLUSTER_ID")

databricks/sdk/credentials_provider.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,18 @@ def token() -> oauth.Token:
407407
return OAuthCredentialsProvider(refreshed_headers, token)
408408

409409

410-
@oauth_credentials_strategy("azdo-oidc", ["host", "client_id"])
410+
@oauth_credentials_strategy(
411+
"azdo-oidc",
412+
[
413+
"host",
414+
"client_id",
415+
"azure_devops_access_token",
416+
"azure_devops_collection_uri",
417+
"azure_devops_project_id",
418+
"azure_devops_plan_id",
419+
"azure_devops_job_id",
420+
],
421+
)
411422
def azure_devops_oidc(cfg: "Config") -> Optional[CredentialsProvider]:
412423
"""
413424
Azure DevOps OIDC authentication uses a Token Supplier to get a JWT Token
@@ -424,12 +435,12 @@ def azure_devops_oidc(cfg: "Config") -> Optional[CredentialsProvider]:
424435
audience = cfg.oidc_endpoints.token_endpoint
425436

426437
# Try to get an idToken. If no supplier returns a token, we cannot use this authentication mode.
427-
id_token = supplier.get_oidc_token(audience)
438+
id_token = supplier.get_oidc_token(audience, cfg)
428439
if not id_token:
429440
return None
430441

431442
def token_source_for(audience: str) -> oauth.TokenSource:
432-
id_token = supplier.get_oidc_token(audience)
443+
id_token = supplier.get_oidc_token(audience, cfg)
433444
if not id_token:
434445
# Should not happen, since we checked it above.
435446
raise Exception("Cannot get Azure DevOps OIDC token")

databricks/sdk/oidc_token_supplier.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,20 @@ class AzureDevOpsOIDCTokenSupplier:
3636
See: https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables
3737
"""
3838

39-
def get_oidc_token(self, audience: str) -> Optional[str]:
39+
def get_oidc_token(self, audience: str, config=None) -> Optional[str]:
4040
# Note: Azure DevOps OIDC tokens have a fixed audience of "api://AzureADTokenExchange"
4141
# The audience parameter is ignored but kept for interface compatibility with other OIDC suppliers
4242

43-
# Check for required Azure DevOps environment variables
44-
access_token = os.environ.get("SYSTEM_ACCESSTOKEN")
45-
collection_uri = os.environ.get("SYSTEM_TEAMFOUNDATIONCOLLECTIONURI")
46-
project_id = os.environ.get("SYSTEM_TEAMPROJECTID")
47-
plan_id = os.environ.get("SYSTEM_PLANID")
48-
job_id = os.environ.get("SYSTEM_JOBID")
49-
hub_name = os.environ.get("SYSTEM_HOSTTYPE", "build") # Default to "build"
43+
# Get Azure DevOps environment variables from config
44+
if config is None:
45+
return None
46+
47+
access_token = config.azure_devops_access_token
48+
collection_uri = config.azure_devops_collection_uri
49+
project_id = config.azure_devops_project_id
50+
plan_id = config.azure_devops_plan_id
51+
job_id = config.azure_devops_job_id
52+
hub_name = config.azure_devops_host_type or "build" # Default to "build"
5053

5154
# Check for required variables
5255
if not all([access_token, collection_uri, project_id, plan_id, job_id]):

0 commit comments

Comments
 (0)