CloudConfigurationManager不会覆盖来自外部文件的设置
本文关键字:外部 文件 设置 覆盖 CloudConfigurationManager | 更新日期: 2023-09-27 18:02:35
我刚刚发现了CloudConfigurationManager
的一个模糊但非常令人沮丧的bug。我正在寻找解决方案,以及(作为旁注)关于报告错误的最佳论坛的提示。我猜这将是一个相对较快的解决办法。
我有一个Azure应用程序服务,连接到DocumentDb的配置设置称为DocumentDB.Endpoint
和DocumentDB.Key
。这些是在f#中使用
let endpoint = config.ReadConfigSetting<string>("DocumentDB.Endpoint")
let key = config.ReadConfigSetting<string>("DocumentDB.Key")
ReadConfigSetting
方法是一个方便的方法,它执行相关的类型转换和默认赋值。在掩护下,它使用CloudConfigurationManager.GetSetting
。出于我们的目的,将调用视为
let endpoint = CloudConfigurationManager.GetSetting("DocumentDB.Endpoint")
let key = CloudConfigurationManager.GetSetting("DocumentDB.Key")
我有一个webjob,在我的文档DB集合上执行cron作业。CloudConfigurationManager
首先从应用程序服务设置中获取设置,如果在应用程序服务设置中没有找到密钥,它将查看我的webjob的app.config
。
在我的QA环境中,我的webjob正在选择正确的端点,但错误的键。这是因为DocumentDb.Endpoint
直接在我的app.config
文件中列出,但DocumentDb.Key
在一个单独的文件中,即.gitignore
d。我不想在Git repo中使用敏感密钥,即使它是私有的,并且凭据仅在app.config和我的外部文件中列出,方便我在本地运行作业。
这是我的设置:
App.config
<appSettings file="keys.config">
<add key="agentUserName" value="<Everyone can read this>" />
<add key="apiHost" value="<and this>" />
<add key="DocumentDB.Endpoint" value="<points to my remote develpment copy of DocumentDB -- looking forward to when I can get a local repo>" />
</appSettings>
keys.config
<appSettings>
<add key="DocumentDB.Key" value="<This is private, so it's in this gitignored file>" />
<add key="agentPassword" value="<I'm not telling you>" />
<add key="TestUserPassword" value="<I'd be an idiot to post this value in a SO question>" />
</appSettings>
你可以看到发生了什么。
CloudConfigurationManager查找DocumentDB值时的预期行为。关键
- 查看DocumentDB值的底层应用服务设置。关键
- 如果存在,使用
- 否则,查看
App.config
- 如果没有,请查看
keys.config
。
CloudConfigurationManager的实际行为
-
keys.config
有值吗? - 然后查看应用服务设置
- 然后
App.config
.
我现在最好的解决办法是在我发布web作业时注释出keys.config
中的值,但这很笨拙。有更好的方法吗?
哪里是最好的地方记录这个问题?
您看过Azure密钥库吗?以下是Azure密钥库的介绍:https://azure.microsoft.com/en-us/documentation/articles/key-vault-get-started/
如果您将DocumentDB秘密存储在Azure密钥库中,您可以将对秘密的访问权限授予应用程序级别。下面是另一篇文章,展示了如何在web应用程序中做到这一点:https://azure.microsoft.com/en-us/documentation/articles/key-vault-use-from-web-application/
希望对你有帮助。
谢谢。
Lengning