gpt4 book ai didi

azure - 使用 .NET 程序集创建 Azure Key Vault (Microsoft.Azure.KeyVault)

转载 作者:行者123 更新时间:2023-12-03 05:58:12 24 4
gpt4 key购买 nike

我正在编写一个 .Net 控制台应用程序来创建 Key Vault,但无法在 Microsoft.Azure.KeyVault 程序集中找到允许创建 Vault 并将服务主体设置为该保管库的类/方法。

有人可以指出我可以用来创建保管库的程序集/类吗?

谢谢

最佳答案

您要查找的类是 Microsoft.Azure.Management.KeyVault 命名空间中的 KeyVaultManagementClient。这是在管理 KeyVault 程序集中定义的,您可以从 NuGet 获取。

enter image description here

执行此操作的代码的主要部分如下所示。但是,请注意,我已经缩写了一些您必须进一步定义和初始化的内容(属性、订阅凭据等)。如果您想查看完整的解决方案,请查看 . NET Azure SDK ,特别是 KeyVaultManagement.Tests项目。

        // The resource group to create the vault in.
const string resourceGroupName = "Vaults-Resource-Group";

// The name of the vault to create.
const string vaultName = "web-app-01-vault";

// Define access policies to keys and secrets (abbreviated just to illustrate...)
var accessPolicy = new AccessPolicyEntry
{
ApplicationId = sp,
PermissionsToKeys = new string[] { "all" },
PermissionsToSecrets = new string[] { "backup", "create", "delete" } //etc. just to name a few
};

// Define vault properties (abbreviated just to illustrate...)
VaultProperties vaultProps = new VaultProperties()
{
EnabledForTemplateDeployment = true,
AccessPolicies = new List<AccessPolicyEntry>()
{
accessPolicy
}
};

// Initialize 'create parameters' to create the vault in "West US"
VaultCreateOrUpdateParameters vaultParams = new VaultCreateOrUpdateParameters(vaultProps, "westus");

// Initialize an instance to the mgmt client
// NOTE: Need to initialize creds derived from SubscriptionCloudCredentials
KeyVaultManagementClient mgmtClient = new KeyVaultManagementClient(creds);

// Create the vault
mgmtClient.Vaults.CreateOrUpdateAsync(resourceGroupName, vaultName, vaultParams);

关于azure - 使用 .NET 程序集创建 Azure Key Vault (Microsoft.Azure.KeyVault),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37276458/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com