【问题标题】:How do you update the Cosmos DB account key used in an Azure Data Factory linked service如何更新 Azure 数据工厂链接服务中使用的 Cosmos DB 帐户密钥
【发布时间】:2021-01-08 21:28:51
【问题描述】:

我正在尝试通过 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”为空。

考虑到错误,typeProperties 在有效负载中不为空。但是,我不确定简单地返回属性是否是正确的做法。

documentation 不包含任何类型的示例定义文件,并且我找不到任何工作示例(也许我正在寻找错误的东西)。

如何正确更新 Cosmos DB 的数据工厂链接服务的密钥?

【问题讨论】:

    标签: powershell azure-powershell azure-data-factory-2


    【解决方案1】:

    Azure 数据工厂链接服务的定义文件应如下所示。更多详情请参考herehere

    {
        "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
     
    

    【讨论】:

    猜你喜欢
    • 2018-08-25
    • 2022-01-16
    • 2021-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-10
    相关资源
    最近更新 更多