我很长时间以来一直在使用 Purview。现在我正在尝试使用 Purview API 和 Powershell 来自动化一些事情。
所以我目前正在做的任务是,使用 FQDN 作为输入获取资产的 GUID。以下是我在研究过程中找到的 Microsoft 的 API 文档。
谁能告诉我如何在 powershell 脚本中使用它?或者,如果这不是正确的文件,请参考正确的文件。
我尝试了以下步骤来调用 Microsoft Purview Rest API 以使用 Powershell 从数据目录创建和列出实体:-
我添加了我的服务主体集合管理员、数据源管理员和数据策展人角色,如下所示:-
向应用程序添加 API 权限以访问 Azure Purview 范围,如下所示:-
我运行下面的 Powershell 代码在 Purview 集合中创建实体,存储帐户 FQDN 如下所示:-
$AppId="<client-id>"
$AppSecret="<client-secret>"
$TokenURI="https://login.microsoftonline.com/<tenant-id>/oauth2/token"
$Resource="https://purview.azure.net"
$BodyRequest="grant_type=client_credentials&client_id=$AppId&client_secret=$AppSecret&resource=$Resource"
$AccessToken=Invoke-RestMethod -Method Post -Uri $TokenURI `
-Body $BodyRequest -ContentType 'application/x-www-form-urlencoded'
$RequestURI="
https://<purviewaccount-name>.purview.azure.com/catalog/api/collections/<collection-name>/entity?api-version=2022-03-01-preview"
$body = @"
{
"referredEntities": {},
"entity": {
"typeName": "azure_storage_account",
"attributes": {
"name": "exampleaccount",
"qualifiedName": "https://exampleaccount.core.windows.net"
}
}
}
"@
$Headers=@{}
$Headers.Add("Authorization","Bearer " + $AccessToken.access_token)
$Result = (Invoke-RestMethod -Uri $RequestURI -Headers $Headers -Method POST -Body $body -Verbose -ContentType 'application/json')
Write-Host $Result
输出:-
Asset with Storage account 是在 Purview 集合中创建的,如下所示:-
控制台:-
传送门:-
我使用以下 API 通过其存储帐户 FQDN 使用 Powershell 代码调用实体:-
API-
GET https://siliconpurview.purview.azure.com/catalog/api/atlas/v2/entity/uniqueAttribute/type/azure_storage_account?minExtInfo=false&ignoreRelationships=true&attr:qualifiedName=https://exampleaccount.core.windows.net
Powershell代码:-
$AppId="<client-id>"
$AppSecret="<client-secret>"
$TokenURI="https://login.microsoftonline.com/<tenant-id>/oauth2/token"
$Resource="https://purview.azure.net"
$BodyRequest="grant_type=client_credentials&client_id=$AppId&client_secret=$AppSecret&resource=$Resource"
$AccessToken=Invoke-RestMethod -Method Post -Uri $TokenURI `
-Body $BodyRequest -ContentType 'application/x-www-form-urlencoded'
$RequestURI="https://<Purview-account-name>.purview.azure.com/catalog/api/atlas/v2/entity/uniqueAttribute/type/azure_storage_account?minExtInfo=false&ignoreRelationships=true&attr:qualifiedName=https://exampleaccount.core.windows.net"
$Headers=@{}
$Headers.Add("Authorization","Bearer " + $AccessToken.access_token)
$Result = (Invoke-RestMethod -Uri $RequestURI -Headers $Headers -Method GET )
Write-Host $Result
输出:-
控制台:-
通过 Postman 调用相同的 API 并获得如下完整的身体响应:-
参考文献:-
azure - 使用 API 移动 Purview 资产 - 堆栈内存溢出