如何更新 Azure 数据工厂链接服务中使用的 Cosmos DB 帐户密钥
How do you update the Cosmos DB account key used in an Azure Data Factory linked service
我正在尝试通过 PowerShell 更新数据工厂 V2 链接服务,但我无法获得工作定义文件。
我的情况是,在轮换 Cosmos DB 帐户密钥后,连接到帐户数据库的数据工厂链接服务应使用新密钥进行更新。为此,我从链接服务中提取现有属性,更新 EncryptedCredential
和 AdditionalProperties.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
失败了 -
Invalid linked service payload, the 'typeProperties' nested in payload is null.
鉴于错误,typeProperties
在负载中不为空。但是,我不确定简单地触发属性是否是正确的做法。
documentation 不包含任何类型的示例定义文件,我找不到任何工作示例(也许我正在搜索错误的东西)。
如何正确更新 Cosmos DB 的数据工厂链接服务的密钥?
Azure 数据工厂链接服务的定义文件应该如下所示。详情请参考here and here.
{
"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
我正在尝试通过 PowerShell 更新数据工厂 V2 链接服务,但我无法获得工作定义文件。
我的情况是,在轮换 Cosmos DB 帐户密钥后,连接到帐户数据库的数据工厂链接服务应使用新密钥进行更新。为此,我从链接服务中提取现有属性,更新 EncryptedCredential
和 AdditionalProperties.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
失败了 -
Invalid linked service payload, the 'typeProperties' nested in payload is null.
鉴于错误,typeProperties
在负载中不为空。但是,我不确定简单地触发属性是否是正确的做法。
documentation 不包含任何类型的示例定义文件,我找不到任何工作示例(也许我正在搜索错误的东西)。
如何正确更新 Cosmos DB 的数据工厂链接服务的密钥?
Azure 数据工厂链接服务的定义文件应该如下所示。详情请参考here and here.
{
"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