如何通过Azure DevOps的API获取用户对存储库的权限?
您可以使用存储库 - 列表 REST API 来获取存储库 ID (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)。然后使用 Permissions Report - Create 创建您的存储库的权限报告。
示例 powershell:
# Define your organization and PAT
$organization = "orgname"
$pat = "your PAT"
# Convert PAT to Base64
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($pat)"))
# Define API URL
$permissionsCreateApiUrl = "https://dev.azure.com/$organization/_apis/permissionsreport?api-version=7.1-preview.1"
# Create permissions report
$body = @{
"descriptors" = @() # List of groups and users to fetch permissions on. An empty list will fetch all groups and users in the organization.
"reportName" = "Permission report for repository name" # Name of the report to create, make it unique
"resources" = @(
@{
"resourceId" = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
"resourceType" = "repo"
}
)
} | ConvertTo-Json
$permissionsCreateResponse = Invoke-RestMethod -Uri $permissionsCreateApiUrl -Headers @{Authorization = "Basic $base64AuthInfo"} -Method Post -Body $body -ContentType "application/json"
# Print report link
$report_downloadLink = $permissionsCreateResponse._downloadLink.href
Write-Host "Report downloadLink : $report_downloadLink"
获得权限报告的下载链接后,您可以下载查看。