2016-05-17 108 views

回答

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

Thanks @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#,我試圖做到這一點 - 它的工作原理,但應該進行測試。

相關問題