2016-05-17 8 views
0

鍵のVaultを作成するための.Netコンソールアプリケーションを作成していますが、Vaultを作成できるMicrosoft.Azure.KeyVaultアセンブリでクラス/メソッドを見つけることができません。サービスプリンシパルをそのボールトに設定します。.NETアセンブリ(Microsoft.Azure.KeyVault)を使用してAzure Key Vaultを作成

誰かがボールトの作成に使用できるアセンブリ/クラスを指摘できますか?何らかの理由で

おかげ

答えて

2

あなたが探しているクラスは、Microsoft.AzureののKeyVaultManagementClientです。 管理 .KeyVault名前空間。これは、NuGetから取得できる管理KeyVaultアセンブリで定義されています。

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); 
+0

ありがとう@Rick。 [KeyVaultManagementClient](https://github.com/Azure/azure-sdk-for-net/blob/master/src/ResourceManagement/KeyVaultManagement/KeyVaultManagement.Tests/VaultOperationsTest.cs)を使用してVaultを作成/更新できます。 – NKDev

0

は、クライアントSDKには、このような機能はありません(あるいは、少なくとも、私ものGithubのレポ上に置かれたコードを経ることで、同様のことを見つけることができませんでしたSDK)。 作成/更新キー格納域にはREST APIがありますので、それを使用して作成することができます。またはPowerShell - Powershell from C#を実行することが可能で、私はそれを試みました - それは動作しますが、テストする必要があります。

関連する問題