private async Task <ArmOperation <VaultResource> > CreateVault() { // Create a Vault first VaultCreateOrUpdateContent parameters = new VaultCreateOrUpdateContent(Location, VaultProperties); parameters.Tags.InitializeFrom(Tags); return(await VaultCollection.CreateOrUpdateAsync(WaitUntil.Completed, VaultName, parameters).ConfigureAwait(false)); }
public async Task KeyVaultManagementVaultTestCompoundIdentityAccessControlPolicy() { AccessPolicy.ApplicationId = Guid.Parse(TestEnvironment.ClientId); VaultProperties.EnableSoftDelete = null; var parameters = new VaultCreateOrUpdateParameters(Location, VaultProperties); parameters.Tags.InitializeFrom(Tags); var createVault = await VaultCollection.CreateOrUpdateAsync(true, vaultName : VaultName, parameters : parameters ).ConfigureAwait(false); var vaultResponse = createVault.Value; ValidateVault(vaultResponse.Data, VaultName, ResGroupName, TestEnvironment.SubscriptionId, TenantIdGuid, Location, "A", SkuName.Standard, true, true, true, true, new[] { AccessPolicy }, Tags); // Get var retrievedVault = await VaultCollection.GetAsync(VaultName); ValidateVault(retrievedVault.Value.Data, VaultName, ResGroupName, TestEnvironment.SubscriptionId, TenantIdGuid, Location, "A", SkuName.Standard, true, true, true, true, new[] { AccessPolicy }, Tags); // Delete await retrievedVault.Value.DeleteAsync(true); Assert.ThrowsAsync <RequestFailedException>(async() => { await VaultCollection.GetAsync(VaultName); }); }
public async Task KeyVaultManagementVaultCreateWithoutAccessPolicies() { IgnoreTestInLiveMode(); VaultProperties vaultProperties = new VaultProperties(TenantIdGuid, new KeyVaultSku(KeyVaultSkuFamily.A, KeyVaultSkuName.Standard)); VaultCreateOrUpdateContent content = new VaultCreateOrUpdateContent(Location, vaultProperties); ArmOperation <VaultResource> rawVault = await VaultCollection.CreateOrUpdateAsync(WaitUntil.Completed, VaultName, content); VaultData createdVault = rawVault.Value.Data; Assert.IsNotNull(createdVault); Assert.AreEqual(VaultName, createdVault.Name); }
public async Task NewCode() { #endif ArmClient armClient = new ArmClient(new DefaultAzureCredential()); Subscription subscription = await armClient.GetDefaultSubscriptionAsync(); ResourceGroup resourceGroup = await subscription.GetResourceGroups().GetAsync("myRgName"); VaultCollection vaultCollection = resourceGroup.GetVaults(); VaultCreateOrUpdateParameters parameters = new VaultCreateOrUpdateParameters(Location.WestUS2, new VaultProperties(Guid.NewGuid(), new Sku(SkuFamily.A, SkuName.Standard))); VaultCreateOrUpdateOperation lro = await vaultCollection.CreateOrUpdateAsync("myVaultName", parameters); Vault vault = lro.Value; #endregion }
public async Task KeyVaultManagementRecoverDeletedVault() { IgnoreTestInLiveMode(); VaultCreateOrUpdateContent parameters = new VaultCreateOrUpdateContent(Location, VaultProperties); parameters.Tags.InitializeFrom(Tags); ArmOperation <VaultResource> createdVault = await VaultCollection.CreateOrUpdateAsync(WaitUntil.Completed, VaultName, parameters).ConfigureAwait(false); VaultResource vaultValue = createdVault.Value; // Delete await vaultValue.DeleteAsync(WaitUntil.Completed); // Get deleted vault Assert.ThrowsAsync <RequestFailedException>(async() => { await VaultCollection.GetAsync(VaultName); }); parameters = new VaultCreateOrUpdateContent(Location, VaultProperties); parameters.Tags.InitializeFrom(Tags); // Recover in default mode ArmOperation <VaultResource> recoveredRawVault = await VaultCollection.CreateOrUpdateAsync(WaitUntil.Completed, VaultName, parameters).ConfigureAwait(false); VaultResource recoveredVault = recoveredRawVault.Value; Assert.True(recoveredVault.Data.IsEqual(vaultValue.Data)); // Get recovered vault Response <VaultResource> getResult = await VaultCollection.GetAsync(VaultName); // Delete await getResult.Value.DeleteAsync(WaitUntil.Completed); VaultProperties.CreateMode = VaultCreateMode.Recover; parameters = new VaultCreateOrUpdateContent(Location, VaultProperties); // Recover in recover mode ArmOperation <VaultResource> recoveredRawVault2 = await VaultCollection.CreateOrUpdateAsync(WaitUntil.Completed, VaultName, parameters).ConfigureAwait(false); VaultResource recoveredVault2 = recoveredRawVault.Value; Assert.True(recoveredVault2.Data.IsEqual(vaultValue.Data)); // Get recovered vault getResult = await VaultCollection.GetAsync(VaultName); // Delete await getResult.Value.DeleteAsync(WaitUntil.Completed); }
public async Task KeyVaultManagementListDeletedVaults() { int n = 3; List <string> resourceIds = new List <string>(); List <Vault> vaultList = new List <Vault>(); var parameters = new VaultCreateOrUpdateParameters(Location, VaultProperties); parameters.Tags.InitializeFrom(Tags); for (int i = 0; i < n; i++) { string vaultName = Recording.GenerateAssetName("sdktestvault"); var createdRawVault = await VaultCollection.CreateOrUpdateAsync(vaultName, parameters).ConfigureAwait(false); var createdVault = createdRawVault.Value; Assert.NotNull(createdVault.Data); Assert.NotNull(createdVault.Data.Id); resourceIds.Add(createdVault.Data.Id); vaultList.Add(createdVault); await createdVault.DeleteAsync().ConfigureAwait(false); var deletedVault = await DeletedVaultCollection.GetAsync(Location).ConfigureAwait(false); Assert.IsTrue(deletedVault.Value.Data.Name.Equals(createdVault.Data.Name)); } var deletedVaults = DeletedVaultCollection.GetAllAsync().ToEnumerableAsync().Result; Assert.NotNull(deletedVaults); foreach (var v in deletedVaults) { var exists = resourceIds.Remove(v.Data.Properties.VaultId); if (exists) { // Purge vault await v.PurgeAsync().ConfigureAwait(false); Assert.ThrowsAsync <RequestFailedException>(async() => await DeletedVaultCollection.GetAsync(Location)); } if (resourceIds.Count == 0) { break; } } Assert.True(resourceIds.Count == 0); }
public async Task KeyVaultManagementListDeletedVaults() { int n = 3; List <string> resourceIds = new List <string>(); List <Vault> vaultList = new List <Vault>(); var parameters = new VaultCreateOrUpdateParameters(Location, VaultProperties); parameters.Tags.InitializeFrom(Tags); for (int i = 0; i < n; i++) { string vaultName = Recording.GenerateAssetName("sdktestvault"); var createdRawVault = await VaultCollection.CreateOrUpdateAsync(true, vaultName, parameters).ConfigureAwait(false); var createdVault = createdRawVault.Value; Assert.NotNull(createdVault.Data); Assert.NotNull(createdVault.Data.Id); resourceIds.Add(createdVault.Data.Id); vaultList.Add(createdVault); await createdVault.DeleteAsync(true).ConfigureAwait(false); var deletedVault = await DeletedVaultCollection.GetAsync(Location, vaultName).ConfigureAwait(false); Assert.IsTrue(deletedVault.Value.Data.Name.Equals(createdVault.Data.Name)); } // TODO -- we need to move the GetDeletedVaults method to its collection, and make sure it to return Resources instead of resource data var deletedVaults = Subscription.GetDeletedVaultsAsync().ToEnumerableAsync().Result; Assert.NotNull(deletedVaults); //foreach (var v in deletedVaults) //{ // var exists = resourceIds.Remove(v.Properties.VaultId); // if (exists) // { // // TODO -- fix this // // Purge vault // await v.PurgeAsync().ConfigureAwait(false); // Assert.ThrowsAsync<RequestFailedException>(async () => await DeletedVaultCollection.GetAsync(Location)); // } // if (resourceIds.Count == 0) // break; //} //Assert.True(resourceIds.Count == 0); }
public async Task KeyVaultManagementRecoverDeletedVault() { var parameters = new VaultCreateOrUpdateParameters(Location, VaultProperties); parameters.Tags.InitializeFrom(Tags); var createdVault = await VaultCollection.CreateOrUpdateAsync(true, VaultName, parameters).ConfigureAwait(false); var vaultValue = createdVault.Value; // Delete await vaultValue.DeleteAsync(true); // Get deleted vault Assert.ThrowsAsync <RequestFailedException>(async() => { await VaultCollection.GetAsync(VaultName); }); parameters = new VaultCreateOrUpdateParameters(Location, VaultProperties); parameters.Tags.InitializeFrom(Tags); // Recover in default mode var recoveredRawVault = await VaultCollection.CreateOrUpdateAsync(true, VaultName, parameters).ConfigureAwait(false); var recoveredVault = recoveredRawVault.Value; Assert.True(recoveredVault.Data.IsEqual(vaultValue.Data)); // Get recovered vault var getResult = await VaultCollection.GetAsync(VaultName); // Delete await getResult.Value.DeleteAsync(true); VaultProperties.CreateMode = CreateMode.Recover; parameters = new VaultCreateOrUpdateParameters(Location, VaultProperties); // Recover in recover mode var recoveredRawVault2 = await VaultCollection.CreateOrUpdateAsync(true, VaultName, parameters).ConfigureAwait(false); var recoveredVault2 = recoveredRawVault.Value; Assert.True(recoveredVault2.Data.IsEqual(vaultValue.Data)); // Get recovered vault getResult = await VaultCollection.GetAsync(VaultName); // Delete await getResult.Value.DeleteAsync(true); }
public async Task CreateKeyVaultDisableSoftDelete() { this.AccessPolicy.ApplicationId = Guid.Parse(TestEnvironment.ClientId); this.VaultProperties.EnableSoftDelete = false; var parameters = new VaultCreateOrUpdateParameters("westeurope", VaultProperties); parameters.Tags.InitializeFrom(Tags); var vault = await VaultCollection.CreateOrUpdateAsync(VaultName, parameters).ConfigureAwait(false); var vaultValue = vault.Value; Assert.False(vaultValue.Data.Properties.EnableSoftDelete); await vaultValue.DeleteAsync(); }
public async Task NewCode() { #region Snippet:Changelog_NewCode ArmClient armClient = new ArmClient(new DefaultAzureCredential()); SubscriptionResource subscription = await armClient.GetDefaultSubscriptionAsync(); ResourceGroupResource resourceGroup = await subscription.GetResourceGroups().GetAsync("myRgName"); VaultCollection vaultCollection = resourceGroup.GetVaults(); VaultCreateOrUpdateParameters parameters = new VaultCreateOrUpdateParameters(AzureLocation.WestUS2, new VaultProperties(Guid.NewGuid(), new KeyVaultSku(KeyVaultSkuFamily.A, KeyVaultSkuName.Standard))); ArmOperation <VaultResource> lro = await vaultCollection.CreateOrUpdateAsync(WaitUntil.Completed, "myVaultName", parameters); VaultResource vault = lro.Value; #endregion }
public async Task KeyVaultManagementListVaults() { IgnoreTestInLiveMode(); int n = 3; int top = 2; VaultProperties.EnableSoftDelete = null; List <string> resourceIds = new List <string>(); List <VaultResource> vaultList = new List <VaultResource>(); for (int i = 0; i < n; i++) { string vaultName = Recording.GenerateAssetName("sdktest-vault-"); VaultCreateOrUpdateContent parameters = new VaultCreateOrUpdateContent(Location, VaultProperties); parameters.Tags.InitializeFrom(Tags); ArmOperation <VaultResource> createdVault = await VaultCollection.CreateOrUpdateAsync(WaitUntil.Completed, vaultName, parameters).ConfigureAwait(false); VaultResource vaultValue = createdVault.Value; Assert.NotNull(vaultValue); Assert.NotNull(vaultValue.Id); resourceIds.Add(vaultValue.Id); vaultList.Add(vaultValue); } AsyncPageable <VaultResource> vaults = VaultCollection.GetAllAsync(top); await foreach (var v in vaults) { Assert.True(resourceIds.Remove(v.Id)); } Assert.True(resourceIds.Count == 0); AsyncPageable <VaultResource> allVaults = VaultCollection.GetAllAsync(top); Assert.NotNull(vaults); // Delete foreach (var item in vaultList) { await item.DeleteAsync(WaitUntil.Completed); } }
public async Task CreateOrUpdate() { #region Snippet:Managing_KeyVaults_CreateAVault VaultCollection vaultCollection = resourceGroup.GetVaults(); string vaultName = "myVault"; Guid tenantIdGuid = new Guid("Your tenantId"); string objectId = "Your Object Id"; IdentityAccessPermissions permissions = new IdentityAccessPermissions { Keys = { new KeyPermission("all") }, Secrets = { new SecretPermission("all") }, Certificates = { new CertificatePermission("all") }, Storage = { new StoragePermission("all") }, }; AccessPolicyEntry AccessPolicy = new AccessPolicyEntry(tenantIdGuid, objectId, permissions); VaultProperties VaultProperties = new VaultProperties(tenantIdGuid, new KeyVaultSku(KeyVaultSkuFamily.A, KeyVaultSkuName.Standard)); VaultProperties.EnabledForDeployment = true; VaultProperties.EnabledForDiskEncryption = true; VaultProperties.EnabledForTemplateDeployment = true; VaultProperties.EnableSoftDelete = true; VaultProperties.VaultUri = new Uri("http://vaulturi.com"); VaultProperties.NetworkAcls = new NetworkRuleSet() { Bypass = "******", DefaultAction = "Allow", IPRules = { new IPRule("1.2.3.4/32"), new IPRule("1.0.0.0/25") } }; VaultProperties.AccessPolicies.Add(AccessPolicy); VaultCreateOrUpdateContent parameters = new VaultCreateOrUpdateContent(AzureLocation.WestUS, VaultProperties); var rawVault = await vaultCollection.CreateOrUpdateAsync(WaitUntil.Started, vaultName, parameters).ConfigureAwait(false); VaultResource vault = await rawVault.WaitForCompletionAsync(); #endregion }
public async Task KeyVaultManagementListDeletedVaults() { IgnoreTestInLiveMode(); int n = 3; List <string> resourceIds = new List <string>(); List <VaultResource> vaultList = new List <VaultResource>(); VaultCreateOrUpdateContent parameters = new VaultCreateOrUpdateContent(Location, VaultProperties); parameters.Tags.InitializeFrom(Tags); for (int i = 0; i < n; i++) { string vaultName = Recording.GenerateAssetName("sdktest-vault-"); ArmOperation <VaultResource> createdRawVault = await VaultCollection.CreateOrUpdateAsync(WaitUntil.Completed, vaultName, parameters).ConfigureAwait(false); VaultResource createdVault = createdRawVault.Value; Assert.NotNull(createdVault.Data); Assert.NotNull(createdVault.Data.Id); resourceIds.Add(createdVault.Data.Id); vaultList.Add(createdVault); await createdVault.DeleteAsync(WaitUntil.Completed).ConfigureAwait(false); Response <DeletedVaultResource> deletedVault = await DeletedVaultCollection.GetAsync(Location, vaultName).ConfigureAwait(false); Assert.IsTrue(deletedVault.Value.Data.Name.Equals(createdVault.Data.Name)); } List <DeletedVaultResource> deletedVaults = Subscription.GetDeletedVaultsAsync().ToEnumerableAsync().Result; Assert.NotNull(deletedVaults); foreach (var v in deletedVaults) { bool exists = resourceIds.Remove(v.Data.Properties.VaultId); if (resourceIds.Count == 0) { break; } } Assert.True(resourceIds.Count == 0); }
public async Task KeyVaultManagementVaultCreateUpdateDelete() { VaultProperties.EnableSoftDelete = null; var parameters = new VaultCreateOrUpdateParameters(Location, VaultProperties); parameters.Tags.InitializeFrom(Tags); var rawVault = await VaultCollection.CreateOrUpdateAsync(true, VaultName, parameters).ConfigureAwait(false); var createdVault = rawVault.Value.Data; ValidateVault(createdVault, VaultName, ResGroupName, TestEnvironment.SubscriptionId, TenantIdGuid, Location, "A", SkuName.Standard, true, true, true, true, // enableSoftDelete defaults to true new[] { AccessPolicy }, VaultProperties.NetworkAcls, Tags); //Update AccessPolicy.Permissions.Secrets.Clear(); AccessPolicy.Permissions.Secrets.Add(SecretPermissions.Get); AccessPolicy.Permissions.Secrets.Add(SecretPermissions.Set); (AccessPolicy.Permissions.Keys as ChangeTrackingList <KeyPermissions>).Reset(); AccessPolicy.Permissions.Storage.Clear(); AccessPolicy.Permissions.Storage.Add(StoragePermissions.Get); AccessPolicy.Permissions.Storage.Add(StoragePermissions.Regeneratekey); createdVault.Properties.AccessPolicies.Clear(); createdVault.Properties.AccessPolicies.Add(AccessPolicy); createdVault.Properties.Sku.Name = SkuName.Premium; parameters = new VaultCreateOrUpdateParameters(Location, createdVault.Properties); parameters.Tags.InitializeFrom(Tags); var rawUpdateVault = await VaultCollection.CreateOrUpdateAsync(true, VaultName, parameters).ConfigureAwait(false); var updateVault = rawUpdateVault.Value.Data; ValidateVault(updateVault, VaultName, ResGroupName, TestEnvironment.SubscriptionId, TenantIdGuid, Location, "A", SkuName.Premium, true, true, true, true, new[] { AccessPolicy }, VaultProperties.NetworkAcls, Tags); var rawRetrievedVault = await VaultCollection.GetAsync(VaultName); var retrievedVault = rawRetrievedVault.Value.Data; ValidateVault(retrievedVault, VaultName, ResGroupName, TestEnvironment.SubscriptionId, TenantIdGuid, Location, "A", SkuName.Premium, true, true, true, true, new[] { AccessPolicy }, VaultProperties.NetworkAcls, Tags); // Delete var deleteVault = await rawRetrievedVault.Value.DeleteAsync(true); Assert.ThrowsAsync <RequestFailedException>(async() => { await VaultCollection.GetAsync(VaultName); }); }
public async Task KeyVaultManagementVaultCreateUpdateDelete() { IgnoreTestInLiveMode(); VaultProperties.EnableSoftDelete = null; VaultCreateOrUpdateContent parameters = new VaultCreateOrUpdateContent(Location, VaultProperties); parameters.Tags.InitializeFrom(Tags); ArmOperation <VaultResource> rawVault = await VaultCollection.CreateOrUpdateAsync(WaitUntil.Completed, VaultName, parameters).ConfigureAwait(false); VaultData createdVault = rawVault.Value.Data; ValidateVault(createdVault, VaultName, ResGroupName, TestEnvironment.SubscriptionId, TenantIdGuid, Location, "A", KeyVaultSkuName.Standard, true, true, true, true, // enableSoftDelete defaults to true new[] { AccessPolicy }, VaultProperties.NetworkRuleSet, Tags); //Update AccessPolicy.Permissions.Secrets.Clear(); AccessPolicy.Permissions.Secrets.Add(SecretPermission.Get); AccessPolicy.Permissions.Secrets.Add(SecretPermission.Set); (AccessPolicy.Permissions.Keys as ChangeTrackingList <KeyPermission>).Reset(); AccessPolicy.Permissions.Storage.Clear(); AccessPolicy.Permissions.Storage.Add(StoragePermission.Get); AccessPolicy.Permissions.Storage.Add(StoragePermission.RegenerateKey); createdVault.Properties.AccessPolicies.Clear(); createdVault.Properties.AccessPolicies.Add(AccessPolicy); createdVault.Properties.Sku.Name = KeyVaultSkuName.Premium; parameters = new VaultCreateOrUpdateContent(Location, createdVault.Properties); parameters.Tags.InitializeFrom(Tags); ArmOperation <VaultResource> rawUpdateVault = await VaultCollection.CreateOrUpdateAsync(WaitUntil.Completed, VaultName, parameters).ConfigureAwait(false); VaultData updateVault = rawUpdateVault.Value.Data; ValidateVault(updateVault, VaultName, ResGroupName, TestEnvironment.SubscriptionId, TenantIdGuid, Location, "A", KeyVaultSkuName.Premium, true, true, true, true, new[] { AccessPolicy }, VaultProperties.NetworkRuleSet, Tags); Response <VaultResource> rawRetrievedVault = await VaultCollection.GetAsync(VaultName); VaultData retrievedVault = rawRetrievedVault.Value.Data; ValidateVault(retrievedVault, VaultName, ResGroupName, TestEnvironment.SubscriptionId, TenantIdGuid, Location, "A", KeyVaultSkuName.Premium, true, true, true, true, new[] { AccessPolicy }, VaultProperties.NetworkRuleSet, Tags); // Delete ArmOperation deleteVault = await rawRetrievedVault.Value.DeleteAsync(WaitUntil.Completed); Assert.ThrowsAsync <RequestFailedException>(async() => { await VaultCollection.GetAsync(VaultName); }); }
public async Task WebAppKeyVaultConnectionCRUD() { string resourceGroupName = Recording.GenerateAssetName("SdkRg"); string webAppName = Recording.GenerateAssetName("SdkWeb"); string vaultName = Recording.GenerateAssetName("SdkVault"); string linkerName = Recording.GenerateAssetName("SdkLinker"); // create resource group await ResourceGroups.CreateOrUpdateAsync(WaitUntil.Completed, resourceGroupName, new Resources.ResourceGroupData(DefaultLocation)); ResourceGroupResource resourceGroup = await ResourceGroups.GetAsync(resourceGroupName); // create web app WebSiteCollection webSites = resourceGroup.GetWebSites(); await webSites.CreateOrUpdateAsync(WaitUntil.Completed, webAppName, new WebSiteData(DefaultLocation)); WebSiteResource webapp = await webSites.GetAsync(webAppName); // create key vault VaultCollection vaults = resourceGroup.GetVaults(); var vaultProperties = new VaultProperties(new Guid(TestEnvironment.TenantId), new KeyVaultSku(KeyVaultSkuFamily.A, KeyVaultSkuName.Standard)); vaultProperties.AccessPolicies.Clear(); await vaults.CreateOrUpdateAsync(WaitUntil.Completed, vaultName, new VaultCreateOrUpdateContent(DefaultLocation, vaultProperties)); VaultResource vault = await vaults.GetAsync(vaultName); // create service linker LinkerResourceCollection linkers = webapp.GetLinkerResources(); var linkerData = new LinkerResourceData { TargetService = new Models.AzureResource { Id = vault.Id, }, AuthInfo = new SystemAssignedIdentityAuthInfo(), ClientType = ClientType.Dotnet, }; await linkers.CreateOrUpdateAsync(WaitUntil.Completed, linkerName, linkerData); // list service linker var linkerResources = await linkers.GetAllAsync().ToEnumerableAsync(); Assert.AreEqual(1, linkerResources.Count); Assert.AreEqual(linkerName, linkerResources[0].Data.Name); // get service linker LinkerResource linker = await linkers.GetAsync(linkerName); Assert.IsTrue(linker.Id.ToString().StartsWith(webapp.Id.ToString(), StringComparison.InvariantCultureIgnoreCase)); Assert.AreEqual(vault.Id.ToString(), (linker.Data.TargetService as AzureResource).Id); Assert.AreEqual(AuthType.SystemAssignedIdentity, linker.Data.AuthInfo.AuthType); // get service linker configurations SourceConfigurationResult configurations = await linker.GetConfigurationsAsync(); foreach (var configuration in configurations.Configurations) { Assert.IsNotNull(configuration.Name); Assert.IsNotNull(configuration.Value); } // delete service linker var operation = await linker.DeleteAsync(WaitUntil.Completed); Assert.IsTrue(operation.HasCompleted); }