Example #1
0
        public async Task WebAppSqlConnectionCRUD()
        {
            string resourceGroupName = Recording.GenerateAssetName("SdkRg");
            string webAppName        = Recording.GenerateAssetName("SdkWeb");
            string sqlServerName     = Recording.GenerateAssetName("SdkSql");
            string sqlDatabaseName   = Recording.GenerateAssetName("SdkSql");
            string sqlUserName       = Recording.GenerateAssetName("SdkSql");
            string sqlPassword       = Recording.GenerateAssetName("SdkPa5$");
            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 sql database
            SqlServerCollection sqlServers    = resourceGroup.GetSqlServers();
            SqlServerData       sqlServerData = new SqlServerData(DefaultLocation)
            {
                AdministratorLogin         = sqlUserName,
                AdministratorLoginPassword = sqlPassword,
            };
            await sqlServers.CreateOrUpdateAsync(WaitUntil.Completed, sqlServerName, sqlServerData);

            SqlServerResource sqlServer = await sqlServers.GetAsync(sqlServerName);

            SqlDatabaseCollection sqlDatabases = sqlServer.GetSqlDatabases();
            await sqlDatabases.CreateOrUpdateAsync(WaitUntil.Completed, sqlDatabaseName, new SqlDatabaseData(DefaultLocation));

            SqlDatabaseResource sqlDatabase = await sqlDatabases.GetAsync(sqlDatabaseName);

            // create service linker
            LinkerResourceCollection linkers = webapp.GetLinkerResources();
            var linkerData = new LinkerResourceData
            {
                TargetService = new Models.AzureResource
                {
                    Id = sqlDatabase.Id,
                },
                AuthInfo = new SecretAuthInfo
                {
                    Name       = sqlUserName,
                    SecretInfo = new ValueSecretInfo
                    {
                        Value = sqlPassword,
                    },
                },
                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(sqlDatabase.Id.ToString(), (linker.Data.TargetService as AzureResource).Id);
            Assert.AreEqual(AuthType.Secret, 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);
        }
Example #2
0
        public async Task WebAppWebPubSubConnectionCRUD()
        {
            string resourceGroupName = Recording.GenerateAssetName("SdkRg");
            string webAppName        = Recording.GenerateAssetName("SdkWeb");
            string webpubsubName     = Recording.GenerateAssetName("SdkWebPubSub");
            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 webpubsub
            WebPubSubCollection webPubSubs    = resourceGroup.GetWebPubSubs();
            WebPubSubData       webPubSubData = new WebPubSubData(DefaultLocation)
            {
                Sku = new WebPubSub.Models.WebPubSubSku("Standard_S1"),
                LiveTraceConfiguration = new WebPubSub.Models.LiveTraceConfiguration(),
                NetworkAcls            = new WebPubSub.Models.WebPubSubNetworkAcls
                {
                    PublicNetwork = new WebPubSub.Models.NetworkAcl(),
                },
            };

            webPubSubData.LiveTraceConfiguration.Categories.Clear();
            webPubSubData.NetworkAcls.PublicNetwork.Allow.Clear();
            webPubSubData.NetworkAcls.PublicNetwork.Deny.Clear();
            webPubSubData.ResourceLogCategories.Clear();
            await webPubSubs.CreateOrUpdateAsync(WaitUntil.Completed, webpubsubName, webPubSubData);

            WebPubSubResource webPubSub = await webPubSubs.GetAsync(webpubsubName);

            // create service linker
            LinkerResourceCollection linkers = webapp.GetLinkerResources();
            var linkerData = new LinkerResourceData
            {
                TargetService = new Models.AzureResource
                {
                    Id = webPubSub.Id,
                },
                AuthInfo   = new SecretAuthInfo(),
                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(webPubSub.Id.ToString(), (linker.Data.TargetService as AzureResource).Id);
            Assert.AreEqual(AuthType.Secret, 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);
        }
        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);
        }