Example #1
0
        protected async Task <string> GetFirstUsableLocationAsync(ProvidersClient providersClient, string resourceProviderNamespace, string resourceType)
        {
            var provider = (await providersClient.GetAsync(resourceProviderNamespace)).Value;

            return(provider.ResourceTypes.Where(
                       (resType) =>
            {
                if (resType.ResourceType == resourceType)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
                       ).First().Locations.FirstOrDefault());
        }
Example #2
0
        protected async Task Initialize()
        {
            var resourceManagementClient = GetResourceManagementClient();

            ResourcesClient         = resourceManagementClient.GetResourcesClient();
            ResourceGroupsClient    = resourceManagementClient.GetResourceGroupsClient();
            ResourceProvidersClient = resourceManagementClient.GetProvidersClient();

            var keyVaultManagementClient = GetKeyVaultManagementClient();

            VaultsClient = keyVaultManagementClient.GetVaultsClient();

            if (Mode == RecordedTestMode.Playback)
            {
                this.ObjectId = Recording.GetVariable(ObjectIdKey, string.Empty);
            }
            else if (Mode == RecordedTestMode.Record)
            {
                var spClient             = new RbacManagementClient(TestEnvironment.TenantId, TestEnvironment.Credential).GetServicePrincipalsClient();
                var servicePrincipalList = spClient.ListAsync($"appId eq '{TestEnvironment.ClientId}'");
                await foreach (var servicePrincipal in servicePrincipalList)
                {
                    this.ObjectId = servicePrincipal.ObjectId;
                    Recording.GetVariable(ObjectIdKey, this.ObjectId);
                    break;
                }
            }
            var provider = (await ResourceProvidersClient.GetAsync("Microsoft.KeyVault")).Value;

            this.Location = provider.ResourceTypes.Where(
                (resType) =>
            {
                if (resType.ResourceType == "vaults")
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
                ).First().Locations.FirstOrDefault();

            ResGroupName = Recording.GenerateAssetName("sdktestrg");
            await ResourceGroupsClient.CreateOrUpdateAsync(ResGroupName, new Resources.Models.ResourceGroup(Location));

            VaultName = Recording.GenerateAssetName("sdktestvault");

            TenantIdGuid = new Guid(TestEnvironment.TenantId);
            Tags         = new Dictionary <string, string> {
                { "tag1", "value1" }, { "tag2", "value2" }, { "tag3", "value3" }
            };

            var permissions = new Permissions
            {
                Keys         = new KeyPermissions[] { new KeyPermissions("all") },
                Secrets      = new SecretPermissions[] { new SecretPermissions("all") },
                Certificates = new CertificatePermissions[] { new CertificatePermissions("all") },
                Storage      = new StoragePermissions[] { new StoragePermissions("all") },
            };

            AccessPolicy = new AccessPolicyEntry(TenantIdGuid, ObjectId, permissions);

            IList <IPRule> ipRules = new List <IPRule>();

            ipRules.Add(new IPRule("1.2.3.4/32"));
            ipRules.Add(new IPRule("1.0.0.0/25"));

            VaultProperties = new VaultProperties(TenantIdGuid, new Sku(SkuName.Standard));


            VaultProperties.EnabledForDeployment         = true;
            VaultProperties.EnabledForDiskEncryption     = true;
            VaultProperties.EnabledForTemplateDeployment = true;
            VaultProperties.EnableSoftDelete             = true;
            VaultProperties.VaultUri    = "";
            VaultProperties.NetworkAcls = new NetworkRuleSet()
            {
                Bypass = "******", DefaultAction = "Allow", IpRules = ipRules, VirtualNetworkRules = null
            };
            VaultProperties.AccessPolicies = new[] { AccessPolicy };
        }