当前位置: 首页 > 知识库问答 >
问题:

Azure Databricks API

吕天逸
2023-03-14

尝试使用数据砖 API 以编程方式处理资源。我正在使用此微软文档向服务主体进行身份验证。

https://learn.microsoft.com/en-us/azure/databricks/dev-tools/api/latest/aad/service-prin-aad-token

但是我收到以下错误

“调用-Rest方法: {”错误“:”invalid_resource“,”error_description“:”AADSTS500011:在租户中找不到名为 https://management.core.azure.com 的资源主体”

这是我的完整剧本。我错过了什么?

$ApiCommand = "clusters/get"

$DataBrick = "https://adb-3522222096750220.0.azuredatabricks.net"

$DataBricksResourceID = ""

$VaultName = ""
$KeyName = ""

$apiEndpointUri = "https://management.core.azure.com"  
$tenantId = ""  
$applicationId = ""  
$secret = Get-AzKeyVaultSecret -VaultName $VaultName -Name $KeyName -AsPlainText

$RequestAccessTokenUri = "https://login.microsoftonline.com/$tenantId/oauth2/token"
$body = "grant_type=client_credentials&client_id=$applicationId&client_secret=$secret&resource=2ff814a6-3304-4ab8-85cb-cd0e6f879c1d" 
$Managementbody = "grant_type=client_credentials&client_id=$applicationId&client_secret=$secret&resource=$apiEndpointUri"  
$contentType = 'application/x-www-form-urlencoded' 

$AccessToken = Invoke-RestMethod -Method Post -Uri $RequestAccessTokenUri -Body $body -ContentType $contentType  
Write-Output $AccessToken
$ManagementToken = Invoke-RestMethod -Method Post -Uri $RequestAccessTokenUri -Body $Managementbody -ContentType $contentType
Write-Output $ManagementToken

$apiuri = $DataBrick +"/api/2.0/$ApiCommand"
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "Bearer " + $AccessToken.access_token)
$headers.Add("X-Databricks-Azure-SP-Management-Token", $ManagementToken.access_token)
$headers.Add("X-Databricks-Azure-Workspace-Resource-Id", $DataBricksResourceID)

Invoke-RestMethod -Uri $apiuri -Headers $headers

共有1个答案

岳泉
2023-03-14

管理终结点 URI 中的尾随 / 字符非常重要 - 您需要按照文档中的格式指定它:https://management.core.windows.net/

还可以将此 SP 添加到工作区本身,然后只需获取一个 AAD 令牌(请参阅文档)。

 类似资料:

相关问答

相关文章

相关阅读