在 zip 文件中提取环境的 RSAT 证书

注释

社区兴趣团体现已从 Yammer 迁移到Microsoft Viva Engage。 若要加入 Viva Engage 社区并参与最新讨论,请填写 “请求访问财务和运营 Viva Engage 社区 ”表单,然后选择要加入的社区。

可以通过 Microsoft Dynamics Lifecycle Services (LCS)通过 LCS 环境 API 获取环境的回归套件自动化工具(RSAT)证书捆绑包。 此 API 为专用证书密码返回 Base 64 编码的 zip 文件和 Base 64 编码的密码。

可以在 回归套件自动化工具安装和配置 页上找到使用 zip 的完整过程。

Permissions

API 应用程序

要调用此 API,需要以下权限之一。 有关权限以及如何选择它们的详细信息,请参阅 数据库移动 API - 身份验证

权限类型 权限(从最低权限到最高权限)
委派(工作或学校帐户) user_impersonation

LCS

在 LCS 中,API OAuth 身份验证中使用的用户必须作为项目所有者或环境管理员添加到项目中。 用户必须接受对项目的邀请。

HTTP 请求

使用以下 GET 终结点提取环境的 RSAT 证书的 zip 文件。

按环境提取 RSAT 证书

GET /environmentinfo/v1/rsatdownload/project/{projectId}/environment/{environmentId}

请求标头

在 HTTP 请求标头中使用以下标头值。

Header 价值
Authorization 持有者 {token} (必需)
“x-ms-version” “2017-09-15” (必需)
Content-Type application/json

请求主体

请勿提供此方法的请求正文。

响应

HTTP

除非未正确进行身份验证,否则响应始终为“200 正常”响应。 请务必使用 IsSuccess 属性来评估作的成功或失败。

Data

资产 Description
CertificateZipEncoded 包含 . 的 zipPFX 和 .Base 64 编码字节数组中的 CER 文件。
CertificateSecretEncoded 作为 Base 64 编码字符串的专用证书的专用机密。 这将更改每个请求。
CertificateThumbprint 专用证书的指纹。
ExpirationDateTimeUTC UTC 格式的日期和时间(以全文格式显示),之后证书无效。
ExpirationISODateTimeUTC UTC 格式的日期和时间(以 ISO 8606 格式显示),之后证书无效。
Filename 要返回的 zip 的文件名。

示例响应

项目级请求的成功响应

{
    "Data": {
        "CertificateZipEncoded": "<base 64-encoded zip>",
        "CertificateSecretEncoded": "<base 64-encoded password>",
        "CertificateThumbprint": "AA11BB22CC33DD44EE55FF66AA77BB88CC99DD00",
        "ExpirationDateTimeUTC": "Sunday, September 4, 2022 4:00:00 AM",
        "ExpirationISODateTimeUTC": "2022-09-04T04:00:00Z",
        "Filename": "RSATCertificate_TestEnv1_20210805-100102.zip"
    },
    "IsSuccess": true,
    "OperationActivityId": "2234bff0-432d-478b-a5ac-1ccb529ee698",
    "ErrorMessage": null,
    "VersionEOL": "9999-12-31T23:59:59.9999999"
}

通过 PowerShell 分析数据

以下示例脚本与 LCS API 通信,将 RSAT 证书的 zip 文件下载到本地计算机。 它在控制台窗口中显示专用证书的密码。 必须提供访问令牌。

# Basic LCS API RSAT certificate zip download script
#
# This will download the RSAT certificate bundle for an environment
# to the current directory and display the private certificate's password
# in the console.
#
# The user used in the API authentication must be added to the
# project as an Environment Admin or Project Owner

# Configuration
$accessToken = "{access token string}";
$projId = {project id integer};
$envId = "{environment id GUID}"
$baseLCSAPI = "lcsapi.lcs.dynamics.com";

$url = "https://$baseLCSAPI/environmentinfo/v1/rsatdownload/project/$projId/environment/$envId"
 
$headers = @{
    "Authorization" = "Bearer $accessToken"
    "x-ms-version" = "2017-09-15"
    "Content-Type" = "application/json"
}

# Reset variable between executions
$certificateResponse = $null 
$shouldRetry = $false

do {
    $shouldRetry = $false

    try {
        # GET request to LCS API
        $certificateResponse = Invoke-RestMethod $url -Method 'GET' -Headers $headers
    } catch {
        # Check if this is a HTTP 429 error
        if ($_.Exception.Response.StatusCode.value__ -eq 429) {

            # Too many requests for this environment, wait and retry
            $shouldRetry = $true
            $retrySeconds = [int]$_.Exception.Response.Headers['Retry-After']
            Write-Host "Too many requests - Retrying in $retrySeconds seconds"
            Start-Sleep -Seconds $retrySeconds
        } else {
            throw
        }
    }
} while($shouldRetry)

if ((-not $certificateResponse.IsSuccess) -or ($certificateResponse.Data -eq $null)) {
    Write-Host $certificateResponse.ErrorMessage
    throw
}

$fileName = $certificateResponse.Data.Filename
$certificateZip = [System.Convert]::FromBase64String($certificateResponse.Data.CertificateZipEncoded)
$certificateSecret = [System.Text.Encoding]::ASCII.GetString(
                            [System.Convert]::FromBase64String(
                                $certificateResponse.Data.CertificateSecretEncoded))

# Save the zip to the local disk.
# Could add unzipping in memory and install certificates to correct local certificate stores.
Set-Content $fileName -Value $certificateZip -Encoding Byte

Write-Host "Certificate bundle downloaded to $fileName with private certificate password $certificateSecret"

速率限制

为了更好地对请求进行负载均衡,此 API 存在速率限制。 这些限制也与 LCS Web 界面共享。

  • 每分钟每个环境的 1 次调用

注释

超过速率限制的请求将被拒绝,并返回“HTTP 429 请求过多”响应。 重试标头将指示请求可以重试后的秒数。