通过ADO的API获取用户对存储库的权限

问题描述 投票:0回答:1

如何通过Azure DevOps的API获取用户对存储库的权限?

azure powershell azure-devops yaml azure-rest-api
1个回答
0
投票

您可以使用存储库 - 列表 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"

获得权限报告的下载链接后,您可以下载查看。

© www.soinside.com 2019 - 2024. All rights reserved.