簡體   English   中英

如何更新 Azure 數據工廠鏈接服務中使用的 Cosmos DB 帳戶密鑰

[英]How do you update the Cosmos DB account key used in an Azure Data Factory linked service

我正在嘗試通過 PowerShell 更新數據工廠 V2 鏈接服務,但我無法獲得工作定義文件。

我的方案是,在輪換 Cosmos DB 帳戶密鑰后,連接到帳戶數據庫的數據工廠鏈接服務應使用新密鑰進行更新。 為此,我從鏈接服務中提取現有屬性,更新EncryptedCredentialAdditionalProperties.typeProperties.encryptedCredential屬性,然后將其重新觸發。

$definitionFile = "{0}/cosmosDbDefinition.json" -f $PSScriptRoot
$definition = (Get-AzDataFactoryV2LinkedService -Name $LinkedServiceName -DataFactoryName $Name -ResourceGroupName $ResourceGroupName).Properties
$definition.EncryptedCredential = ConvertTo-SecureString -String $key -AsPlainText
Set-Content -Path $definitionFile -Value ($definition | ConvertTo-Json)
Set-AzDataFactoryV2LinkedService -Name $Name -DataFactoryName $DataFactoryName -ResourceGroupName $ResourceGroupName -DefinitionFile $definitionFile -Force

但是,由於Set-AzDataFactoryV2LinkedService失敗,我顯然做錯了什么 -

鏈接服務負載無效,負載中嵌套的“typeProperties”為 null。

考慮到錯誤,有效載荷中的typeProperties不是 null。 但是,我不確定簡單地返回屬性是否是正確的做法。

文檔不包含任何類型的示例定義文件,而且我找不到任何可用的示例(也許我正在搜索錯誤的東西)。

如何正確更新 Cosmos DB 的數據工廠鏈接服務的密鑰?

Azure 數據工廠鏈接服務的定義文件應該如下所示。 有關詳細信息,請參閱此處此處

{
    "name": "<Name of the linked service>",
    "properties": {
        "type": "<Type of the linked service>",
        "typeProperties": {
              "<data store or compute-specific type properties>"
        },
        "connectVia": {
            "referenceName": "<name of Integration Runtime>",
            "type": "IntegrationRuntimeReference"
        }
    }
}

如果要更新Azure CosmosDB賬戶密鑰,請參考以下腳本

$key="<account key>"
$definition = (Get-AzDataFactoryV2LinkedService -Name $LinkedServiceName -DataFactoryName $Name -ResourceGroupName $ResourceGroupName).Properties
$newdef=@{
  "properties" =@{
    "type"="CosmosDb"
    "typeProperties"= @{
      "connectionString"= $definition.ConnectionString+ "AccountKey=$($key)"
     
    }
  
  }
} | ConvertTo-Json -Depth 10

$newdef | Out-File E:\test.json

Set-AzDataFactoryV2LinkedService -Name $LinkedServiceName -DataFactoryName $Name -ResourceGroupName $ResourceGroupName -DefinitionFile E:\test.json
 

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM