创建和处置秘密

发布于 2025-02-13 21:19:02 字数 119 浏览 1 评论 0原文

如何从azure.security.keyvault.secrets创建和处置SecretClient?我从keyVaultClient迁移,似乎找不到太多的文档。

How do I create and dispose of SecretClient from Azure.Security.KeyVault.Secrets? I'm migrating from KeyVaultClient and can't seem to find much documentation on this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

紫瑟鸿黎 2025-02-20 21:19:05

根据应用程序的用例,SecretClient提供 同步和异步 活动。您可以在初始化秘密级别后与Azure密钥保险库中的秘密进行交互。

创建秘密:

KeyVaultSecret secret = client.SetSecret("secret-name", "secret-value");

Console.WriteLine(secret.Name);
Console.WriteLine(secret.Value);
Console.WriteLine(secret.Properties.Version);
Console.WriteLine(secret.Properties.Enabled);

startDeletesecret删除存储在Azure键库中的秘密。当 soft-delete 未启用Azure钥匙库永久处理秘密

DeleteSecretOperation operation = client.StartDeleteSecret("secret-name");

DeletedSecret secret = operation.Value;
Console.WriteLine(secret.Name);
Console.WriteLine(secret.Value);

有关更多信息,请请参阅下面的链接

azure.security.keyvault.secrets

azure / azure-sdk-for-net

Depending on the use case of an application, a SecretClient offers both synchronous and asynchronous activities. You can interact with secrets in Azure Key Vault once a SecretClient has been initialised.

Creating secret :

KeyVaultSecret secret = client.SetSecret("secret-name", "secret-value");

Console.WriteLine(secret.Name);
Console.WriteLine(secret.Value);
Console.WriteLine(secret.Properties.Version);
Console.WriteLine(secret.Properties.Enabled);

StartDeleteSecret to delete a secret stored in the Azure Key Vault. When soft-delete is not enabled for the Azure Key Vault permanently disposes the secret.

DeleteSecretOperation operation = client.StartDeleteSecret("secret-name");

DeletedSecret secret = operation.Value;
Console.WriteLine(secret.Name);
Console.WriteLine(secret.Value);

For more information in detail, please refer below links:

Azure.Security.KeyVault.Secrets

Azure/azure-sdk-for-net

爱的那么颓废 2025-02-20 21:19:04

有一篇非常好的文章解释了Azure SDK的客户如何工作 - azure sdk .net客户端的寿命管理

  • 客户lifetime :Azure SDK客户端寿命管理的主要规则是:将客户视为Singletons
  • 线程安全:客户端是线程安全。模型不是线程安全。
  • 客户是不可变的
  • 客户不可销售:共享httpclient作为默认值:一个问题经常出现的问题是,为什么不基于HTTP的Azure客户端实现iDisposable,而内部则使用代码> httpclient 可容纳的?默认情况下,所有Azure SDK客户端都使用单个共享httpclient实例,并且不要创建任何需要积极释放的其他资源。共享客户端实例在整个应用程序寿命中都存在。

来自 azure键保管库秘密客户端库.net ,有关于如何使用新客户的许多示例:

// Create a new secret client using the default credential from Azure.Identity using environment variables previously set,
// including AZURE_CLIENT_ID, AZURE_CLIENT_SECRET, and AZURE_TENANT_ID.
var client = new SecretClient(vaultUri: new Uri(vaultUrl), credential: new DefaultAzureCredential());

// Create a new secret using the secret client.
KeyVaultSecret secret = client.SetSecret("secret-name", "secret-value");

// Retrieve a secret using the secret client.
secret = client.GetSecret("secret-name");

There is a really good article explaining how Azure SDK's clients work - Lifetime management for Azure SDK .NET clients:

  • Client lifetime: The main rule of Azure SDK client lifetime management is: treat clients as singletons.
  • Thread-safety: Clients are thread-safe. Models are not thread-safe.
  • Clients are immutable
  • Clients are not disposable: Shared HttpClient as default: One question that comes up often is why aren’t HTTP-based Azure clients implementing IDisposable while internally using an HttpClient that is disposable? All Azure SDK clients, by default, use a single shared HttpClient instance and don’t create any other resources that need to be actively freed. The shared client instance persists throughout the entire application lifetime.

From Azure Key Vault secret client library for .NET, there are lots of samples on how to use the new clients:

// Create a new secret client using the default credential from Azure.Identity using environment variables previously set,
// including AZURE_CLIENT_ID, AZURE_CLIENT_SECRET, and AZURE_TENANT_ID.
var client = new SecretClient(vaultUri: new Uri(vaultUrl), credential: new DefaultAzureCredential());

// Create a new secret using the secret client.
KeyVaultSecret secret = client.SetSecret("secret-name", "secret-value");

// Retrieve a secret using the secret client.
secret = client.GetSecret("secret-name");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文