如何在一次呼叫Azure密钥保管库中获取所有机密 [英] How to get all secrets in one call Azure key vault
问题描述
我正在使用示例代码在此处进行解释
I am using sample code explain here
https://github.com/Azure-Samples/app-service-msi-keyvault-dotnet
但是他们只解释了如何获得单一秘密而不是秘密清单.
but they only explained how can we get single secrete not list of secrete.
为了获得所有秘密,我正在使用此代码示例
so to get all secrete I'm using this code sample
var all = kv.GetSecretsAsync(url).GetAwaiter().GetResult();
foreach (var secret in all)
{
secretlist.Add(secret.Id);
}
但是它仅获取秘密ID,而不是值.我也想获得所有秘密的价值,所以任何人都可以帮助我做到这一点吗?
but it is only getting the secret id, not value. I want to get all secrets value also so can anyone help how I can do this?
推荐答案
查看文档, SecretItem
,它不包含值,而仅包含秘密元数据.
Looking at the documentation, the KeyVaultClient
Class doesn't contain a method to get all secrets including their values. The GetSecrets
method 'List secrets in a specified key vault.' and returns a list with items of type SecretItem
, which doesn't contain the value but only contains secret metadata.
This is in line with the Key Vault REST API, where there's a GetSecrets that returns... you guessed it... a list of SecretItems.
长话短说:如果想要所有秘密的所有值,则必须迭代列表并明确获取每个秘密.
Long story short: if you want all values of all secrets, you have to iterate the list and get every one explicitly.
这篇关于如何在一次呼叫Azure密钥保管库中获取所有机密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!