问题描述
我正在编写.Net控制台应用程序以创建Key Vault,但无法在Microsoft.Azure.KeyVault程序集中找到允许创建Vault并将该服务主体设置为该Vault的类/方法.
I am writing a .Net console application to create Key Vault but not able to find class/method in Microsoft.Azure.KeyVault assembly that allows creating Vault and setting service principal to that vault.
有人可以指出我可以用来创建保管库的程序集/类吗.
Can someone please point me to the assembly/class that i can use to create vault.
谢谢
推荐答案
您要查找的类是Microsoft.Azure中的 KeyVaultManagementClient . 管理 .KeyVault命名空间.您可以从NuGet中获得的管理KeyVault程序集中对此进行了定义.
The class you are looking for is the KeyVaultManagementClient in the Microsoft.Azure.Management.KeyVault namespace. This is defined in the management KeyVault assembly you can get from NuGet.
执行此操作的代码主要部分如下所示.但是,请注意,我已经缩写了一些东西(属性,订阅凭据等),您将不得不对其进行进一步的定义和初始化.如果您想查看完整的解决方案,请查看. NET Azure SDK中的示例,尤其是 KeyVaultManagement.Tests 项目.
The main parts of the code to do this are shown below. However, be advised that I have abbreviated some things (properties, subscription credentials, etc.) that you will have to further define and initialize. If you want to see a complete solution check out the samples in the .NET Azure SDK, in particular, the KeyVaultManagement.Tests project.
// 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);
这篇关于使用.NET程序集创建Azure Key Vault(Microsoft.Azure.KeyVault)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!