首页 > 解决方案 > 如何在 Data Factory v2 的自定义活动中读取安全字符串?

问题描述

我目前有一个使用自定义活动的 DFv2 管道,我正在尝试弄清楚如何读取传递给自定义活动的安全字符串。

我想这样做的原因是我的自定义活动可以将此安全字符串添加为对外部 API 的请求的一部分。

这是我的自定义活动的简化版本:

{ "name": "CustomActivity", "type": "Custom", "policy": { "timeout": "7.00:00:00", "retry": 0, "retryIntervalInSeconds": 30, "secureOutput": false, "secureInput": false }, "typeProperties": { "command": "CustomCode.exe", "resourceLinkedService": { "referenceName": "AzureStorageLinkedService", "type": "LinkedServiceReference" }, "folderPath": "foldercontainingcustomcode", "extendedProperties": { "url": "sampleUrl", "apiKey": { "type": "SecureString", "value": "**********" } }, "referenceObjects": { "linkedServices": [ { "referenceName": "AzureStorageLinkedService", "type": "LinkedServiceReference" } ], "datasets": [ ] } }, "linkedServiceName": { "referenceName": "AzureBatchLinkedService", "type": "LinkedServiceReference" } }

这是一些示例自定义代码:

class Program
{
    static void Main(string[] args)
    {
        dynamic activity = JsonConvert.DeserializeObject(File.ReadAllText("activity.json"));
        dynamic apiKey = activity.typeProperties.extendedProperties.apiKey.value;
    }
}

我的问题是:我怎样才能做到这一点,因为直接读取 apiKey 只会读取字符串 '*****' ?

标签: azureazure-data-factoryazure-data-factory-2

解决方案


出于安全原因,数据工厂在任何情况下都不会返回安全字符串。

如果您想在自定义 exe 中使用密钥,可以将其作为 JSON 中的加密纯字符串保存,并使用您的证书或对称密钥在代码中对其进行解密。或者您可以引用 Azure Key Vault,以便您也可以在代码中访问它。


推荐阅读