Esempio n. 1
0
        public async Task UpdateOriginGroups()
        {
            #region Snippet:Managing_OriginGroups_UpdateAnOriginGroup
            // First we need to get the cdn origin group collection from the specific endpoint
            ProfileResource profile = await resourceGroup.GetProfiles().GetAsync("myProfile");

            CdnEndpointResource endpoint = await profile.GetCdnEndpoints().GetAsync("myEndpoint");

            CdnOriginGroupCollection originGroupCollection = endpoint.GetCdnOriginGroups();
            // Now we can get the origin group with GetAsync()
            CdnOriginGroupResource originGroup = await originGroupCollection.GetAsync("myOriginGroup");

            // With UpdateAsync(), we can update the origin group
            PatchableCdnOriginGroupData input = new PatchableCdnOriginGroupData()
            {
                HealthProbeSettings = new HealthProbeParameters
                {
                    ProbePath              = "/healthz",
                    ProbeRequestType       = HealthProbeRequestType.Head,
                    ProbeProtocol          = ProbeProtocol.Https,
                    ProbeIntervalInSeconds = 60
                }
            };
            ArmOperation <CdnOriginGroupResource> lro = await originGroup.UpdateAsync(WaitUntil.Completed, input);

            originGroup = lro.Value;
            #endregion Snippet:Managing_OriginGroups_UpdateAnOriginGroup
        }
        public async Task CreateOrUpdate()
        {
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

            ResourceGroupResource rg = await CreateResourceGroup(subscription, "testRg-");

            string          cdnProfileName = Recording.GenerateAssetName("profile-");
            ProfileResource cdnProfile     = await CreateCdnProfile(rg, cdnProfileName, CdnSkuName.StandardMicrosoft);

            string cdnEndpointName          = Recording.GenerateAssetName("endpoint-");
            CdnEndpointResource cdnEndpoint = await CreateCdnEndpoint(cdnProfile, cdnEndpointName);

            Assert.AreEqual(cdnEndpointName, cdnEndpoint.Data.Name);
            Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await cdnProfile.GetCdnEndpoints().CreateOrUpdateAsync(WaitUntil.Completed, null, cdnEndpoint.Data));
            Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await cdnProfile.GetCdnEndpoints().CreateOrUpdateAsync(WaitUntil.Completed, cdnEndpointName, null));
        }
        public async Task LoadAndPurge()
        {
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

            ResourceGroupResource rg = await CreateResourceGroup(subscription, "testRg-");

            string          cdnProfileName = Recording.GenerateAssetName("profile-");
            ProfileResource cdnProfile     = await CreateCdnProfile(rg, cdnProfileName, CdnSkuName.StandardVerizon);

            string            cdnEndpointName   = Recording.GenerateAssetName("endpoint-");
            CdnEndpointData   cdnEndpointData   = ResourceDataHelper.CreateEndpointData();
            DeepCreatedOrigin deepCreatedOrigin = new DeepCreatedOrigin("testOrigin")
            {
                HostName = "testsa4dotnetsdk.blob.core.windows.net"
            };

            cdnEndpointData.Origins.Add(deepCreatedOrigin);
            var lro = await cdnProfile.GetCdnEndpoints().CreateOrUpdateAsync(WaitUntil.Completed, cdnEndpointName, cdnEndpointData);

            CdnEndpointResource cdnEndpoint     = lro.Value;
            PurgeOptions        purgeParameters = new PurgeOptions(new List <string>
            {
                "/*"
            });

            Assert.DoesNotThrowAsync(async() => await cdnEndpoint.PurgeContentAsync(WaitUntil.Completed, purgeParameters));
            LoadOptions loadParameters = new LoadOptions(new List <string>
            {
                "/testfile/file1.txt"
            });

            Assert.DoesNotThrowAsync(async() => await cdnEndpoint.LoadContentAsync(WaitUntil.Completed, loadParameters));
        }
        public async Task List()
        {
            //In this test, the CName mapping from custom domain "customdomaintest-2.azuretest.net" to endpoint "testEndpoint4dotnetsdk.azureedge.net" is created in advance.
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

            ResourceGroupResource rg = await subscription.GetResourceGroups().GetAsync("CdnTest");

            ProfileResource cdnProfile = await rg.GetProfiles().GetAsync("testProfile");

            CdnEndpointResource cdnEndpoint = await cdnProfile.GetCdnEndpoints().GetAsync("testEndpoint4dotnetsdk");

            string cdnCustomDomainName = Recording.GenerateAssetName("customDomain-");
            string hostName            = "customdomaintest-2.azuretest.net";

            _ = await CreateCdnCustomDomain(cdnEndpoint, cdnCustomDomainName, hostName);

            int count = 0;

            await foreach (var tempCustomDomain in cdnEndpoint.GetCdnCustomDomains().GetAllAsync())
            {
                if (tempCustomDomain.Data.HostName.Equals("customdomaintest-2.azuretest.net"))
                {
                    count++;
                }
            }
            Assert.AreEqual(count, 1);
        }
        public async Task Get()
        {
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

            ResourceGroupResource rg = await CreateResourceGroup(subscription, "testRg-");

            string          cdnProfileName = Recording.GenerateAssetName("profile-");
            ProfileResource cdnProfile     = await CreateCdnProfile(rg, cdnProfileName, CdnSkuName.StandardMicrosoft);

            string cdnEndpointName          = Recording.GenerateAssetName("endpoint-");
            CdnEndpointResource cdnEndpoint = await CreateCdnEndpoint(cdnProfile, cdnEndpointName);

            CdnEndpointResource getCdnEndpoint = await cdnProfile.GetCdnEndpoints().GetAsync(cdnEndpointName);

            ResourceDataHelper.AssertValidEndpoint(cdnEndpoint, getCdnEndpoint);
            Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await cdnProfile.GetCdnEndpoints().GetAsync(null));
        }
Esempio n. 6
0
        protected async Task <CdnEndpointResource> CreateCdnEndpoint(ProfileResource profile, string endpointName)
        {
            CdnEndpointData   input             = ResourceDataHelper.CreateEndpointData();
            DeepCreatedOrigin deepCreatedOrigin = ResourceDataHelper.CreateDeepCreatedOrigin();

            input.Origins.Add(deepCreatedOrigin);
            var lro = await profile.GetCdnEndpoints().CreateOrUpdateAsync(WaitUntil.Completed, endpointName, input);

            return(lro.Value);
        }
Esempio n. 7
0
        public async Task DeleteOriginGroups()
        {
            #region Snippet:Managing_OriginGroups_DeleteAnOriginGroup
            // First we need to get the cdn origin group collection from the specific endpoint
            ProfileResource profile = await resourceGroup.GetProfiles().GetAsync("myProfile");

            CdnEndpointResource endpoint = await profile.GetCdnEndpoints().GetAsync("myEndpoint");

            CdnOriginGroupCollection originGroupCollection = endpoint.GetCdnOriginGroups();
            // Now we can get the origin group with GetAsync()
            CdnOriginGroupResource originGroup = await originGroupCollection.GetAsync("myOriginGroup");

            // With DeleteAsync(), we can delete the origin group
            await originGroup.DeleteAsync(WaitUntil.Completed);

            #endregion Snippet:Managing_OriginGroups_DeleteAnOriginGroup
        }
Esempio n. 8
0
        public async Task ListOriginGroups()
        {
            #region Snippet:Managing_OriginGroups_ListAllOriginGroups
            // First we need to get the cdn origin group collection from the specific endpoint
            ProfileResource profile = await resourceGroup.GetProfiles().GetAsync("myProfile");

            CdnEndpointResource endpoint = await profile.GetCdnEndpoints().GetAsync("myEndpoint");

            CdnOriginGroupCollection originGroupCollection = endpoint.GetCdnOriginGroups();
            // With GetAllAsync(), we can get a list of the origin group in the collection
            AsyncPageable <CdnOriginGroupResource> response = originGroupCollection.GetAllAsync();
            await foreach (CdnOriginGroupResource originGroup in response)
            {
                Console.WriteLine(originGroup.Data.Name);
            }
            #endregion Snippet:Managing_OriginGroups_ListAllOriginGroups
        }
        public async Task CreateOrUpdate()
        {
            //In this test, the CName mapping from custom domain "customdomaintest-1.azuretest.net" to endpoint "testEndpoint4dotnetsdk.azureedge.net" is created in advance.
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

            ResourceGroupResource rg = await subscription.GetResourceGroups().GetAsync("CdnTest");

            ProfileResource cdnProfile = await rg.GetProfiles().GetAsync("testProfile");

            CdnEndpointResource cdnEndpoint = await cdnProfile.GetCdnEndpoints().GetAsync("testEndpoint4dotnetsdk");

            string cdnCustomDomainName = Recording.GenerateAssetName("customDomain-");
            string hostName            = "customdomaintest-1.azuretest.net";
            CdnCustomDomainResource cdnCustomDomain = await CreateCdnCustomDomain(cdnEndpoint, cdnCustomDomainName, hostName);

            Assert.AreEqual(cdnCustomDomainName, cdnCustomDomain.Data.Name);
            Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await cdnEndpoint.GetCdnCustomDomains().CreateOrUpdateAsync(WaitUntil.Completed, cdnCustomDomainName, null));
        }
Esempio n. 10
0
        public async Task Disable()
        {
            //In this test, the CName mapping from custom domain "customdomaintest5.azuretest.net" to endpoint "testEndpoint4dotnetsdk.azureedge.net" is created in advance.
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

            ResourceGroupResource rg = await subscription.GetResourceGroups().GetAsync("CdnTest");

            ProfileResource cdnProfile = await rg.GetProfiles().GetAsync("testProfile");

            CdnEndpointResource cdnEndpoint = await cdnProfile.GetCdnEndpoints().GetAsync("testEndpoint4dotnetsdk");

            string cdnCustomDomainName = "customdomaintest5-azuretest-net";
            CdnCustomDomainResource cdnCustomDomain = await cdnEndpoint.GetCdnCustomDomains().GetAsync(cdnCustomDomainName);

            var lro = await cdnCustomDomain.DisableCustomHttpsAsync(WaitUntil.Completed);

            CdnCustomDomainResource disabledCdnCustomDomain = lro.Value;

            Assert.AreEqual(disabledCdnCustomDomain.Data.CustomHttpsProvisioningState, CustomHttpsProvisioningState.Disabled);
        }
Esempio n. 11
0
        protected async Task <CdnEndpointResource> CreateCdnEndpointWithOriginGroup(ProfileResource profile, string endpointName)
        {
            CdnEndpointData        input                  = ResourceDataHelper.CreateEndpointData();
            DeepCreatedOrigin      deepCreatedOrigin      = ResourceDataHelper.CreateDeepCreatedOrigin();
            DeepCreatedOriginGroup deepCreatedOriginGroup = ResourceDataHelper.CreateDeepCreatedOriginGroup();

            deepCreatedOriginGroup.Origins.Add(new WritableSubResource
            {
                Id = new ResourceIdentifier($"{profile.Id}/endpoints/{endpointName}/origins/{deepCreatedOrigin.Name}")
            });
            input.Origins.Add(deepCreatedOrigin);
            input.OriginGroups.Add(deepCreatedOriginGroup);
            input.DefaultOriginGroup = new EndpointPropertiesUpdateParametersDefaultOriginGroup
            {
                Id = new ResourceIdentifier($"{profile.Id}/endpoints/{endpointName}/originGroups/{deepCreatedOriginGroup.Name}")
            };
            var lro = await profile.GetCdnEndpoints().CreateOrUpdateAsync(WaitUntil.Completed, endpointName, input);

            return(lro.Value);
        }
Esempio n. 12
0
        public async Task CreateOriginGroups()
        {
            #region Snippet:Managing_OriginGroups_CreateAnOriginGroup
            // Create a new cdn profile
            string profileName = "myProfile";
            var    input1      = new ProfileData(AzureLocation.WestUS, new CdnSku {
                Name = CdnSkuName.StandardMicrosoft
            });
            ArmOperation <ProfileResource> lro1 = await resourceGroup.GetProfiles().CreateOrUpdateAsync(WaitUntil.Completed, profileName, input1);

            ProfileResource profile = lro1.Value;
            // Get the cdn endpoint collection from the specific ProfileResource and create an endpoint
            string endpointName = "myEndpoint";
            var    input2       = new CdnEndpointData(AzureLocation.WestUS)
            {
                IsHttpAllowed    = true,
                IsHttpsAllowed   = true,
                OptimizationType = OptimizationType.GeneralWebDelivery
            };
            DeepCreatedOrigin deepCreatedOrigin = new DeepCreatedOrigin("myOrigin")
            {
                HostName = "testsa4dotnetsdk.blob.core.windows.net",
                Priority = 3,
                Weight   = 100
            };
            input2.Origins.Add(deepCreatedOrigin);
            ArmOperation <CdnEndpointResource> lro2 = await profile.GetCdnEndpoints().CreateOrUpdateAsync(WaitUntil.Completed, endpointName, input2);

            CdnEndpointResource endpoint = lro2.Value;
            // Get the cdn origin group collection from the specific endpoint and create an origin group
            string originGroupName = "myOriginGroup";
            var    input3          = new CdnOriginGroupData();
            input3.Origins.Add(new WritableSubResource
            {
                Id = new ResourceIdentifier($"{endpoint.Id}/origins/myOrigin")
            });
            ArmOperation <CdnOriginGroupResource> lro3 = await endpoint.GetCdnOriginGroups().CreateOrUpdateAsync(WaitUntil.Completed, originGroupName, input3);

            CdnOriginGroupResource originGroup = lro3.Value;
            #endregion Snippet:Managing_OriginGroups_CreateAnOriginGroup
        }
        public async Task EnableAndDisable()
        {
            //In this test, the CName mapping from custom domain "customdomaintest-5.azuretest.net" to endpoint "testEndpoint4dotnetsdk.azureedge.net" is created in advance.
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

            ResourceGroupResource rg = await subscription.GetResourceGroups().GetAsync("CdnTest");

            ProfileResource cdnProfile = await rg.GetProfiles().GetAsync("testProfile");

            CdnEndpointResource cdnEndpoint = await cdnProfile.GetCdnEndpoints().GetAsync("testEndpoint4dotnetsdk");

            string cdnCustomDomainName = Recording.GenerateAssetName("customDomain-");
            string hostName            = "customdomaintest-5.azuretest.net";
            CdnCustomDomainResource cdnCustomDomain = await CreateCdnCustomDomain(cdnEndpoint, cdnCustomDomainName, hostName);

            Assert.ThrowsAsync <RequestFailedException>(async() => await cdnCustomDomain.DisableCustomHttpsAsync(WaitUntil.Completed));
            CdnManagedHttpsOptions customDomainHttpsOptions = new CdnManagedHttpsOptions(ProtocolType.ServerNameIndication, new CdnCertificateSourceParameters(CdnCertificateSourceParametersOdataType.MicrosoftAzureCdnModelsCdnCertificateSourceParameters, CertificateType.Dedicated));

            Assert.DoesNotThrowAsync(async() => await cdnCustomDomain.EnableCustomHttpsAsync(WaitUntil.Completed, customDomainHttpsOptions));
            Assert.DoesNotThrowAsync(async() => await cdnCustomDomain.DisableCustomHttpsAsync(WaitUntil.Completed));
        }
        public async Task List()
        {
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

            ResourceGroupResource rg = await CreateResourceGroup(subscription, "testRg-");

            string          cdnProfileName = Recording.GenerateAssetName("profile-");
            ProfileResource cdnProfile     = await CreateCdnProfile(rg, cdnProfileName, CdnSkuName.StandardMicrosoft);

            string cdnEndpointName = Recording.GenerateAssetName("endpoint-");

            _ = await CreateCdnEndpoint(cdnProfile, cdnEndpointName);

            int count = 0;

            await foreach (var tempEndpoint in cdnProfile.GetCdnEndpoints().GetAllAsync())
            {
                count++;
            }
            Assert.AreEqual(count, 1);
        }
        public async Task Delete()
        {
            //In this test, the CName mapping from custom domain "customdomaintest4.azuretest.net" to endpoint "testEndpoint4dotnetsdk.azureedge.net" is created in advance.
            //The CName mapping needs to be deleted before deleting the custom domain.
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

            ResourceGroupResource rg = await subscription.GetResourceGroups().GetAsync("CdnTest");

            ProfileResource cdnProfile = await rg.GetProfiles().GetAsync("testProfile");

            CdnEndpointResource cdnEndpoint = await cdnProfile.GetCdnEndpoints().GetAsync("testEndpoint4dotnetsdk");

            string cdnCustomDomainName = "customdomaintest4-azuretest-net";
            var    lro = await cdnEndpoint.GetCdnCustomDomains().GetAsync(cdnCustomDomainName);

            CdnCustomDomainResource cdnCustomDomain = lro.Value;
            await cdnCustomDomain.DeleteAsync(WaitUntil.Completed);

            var ex = Assert.ThrowsAsync <RequestFailedException>(async() => await cdnCustomDomain.GetAsync());

            Assert.AreEqual(404, ex.Status);
        }
        public async Task EnableAndDisable()
        {
            //In this test, the CName mapping from custom domain "customdomaintest5.azuretest.net" to endpoint "testEndpoint4dotnetsdk.azureedge.net" is created in advance.
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

            ResourceGroupResource rg = await subscription.GetResourceGroups().GetAsync("CdnTest");

            ProfileResource cdnProfile = await rg.GetProfiles().GetAsync("testProfile");

            CdnEndpointResource cdnEndpoint = await cdnProfile.GetCdnEndpoints().GetAsync("testEndpoint4dotnetsdk");

            string cdnCustomDomainName = "customdomaintest5-azuretest-net";
            var    lro = await cdnEndpoint.GetCdnCustomDomains().GetAsync(cdnCustomDomainName);

            CdnCustomDomainResource cdnCustomDomain = lro.Value;

            Assert.ThrowsAsync <RequestFailedException>(async() => await cdnCustomDomain.DisableCustomHttpsAsync());
            CdnManagedHttpsOptions  customDomainHttpsOptions = new CdnManagedHttpsOptions(ProtocolType.ServerNameIndication, new CdnCertificateSourceParameters(CdnCertificateSourceParametersTypeName.CdnCertificateSourceParameters, CertificateType.Dedicated));
            CdnCustomDomainResource enabledCdnCustomDomain   = await cdnCustomDomain.EnableCustomHttpsAsync(customDomainHttpsOptions);

            Assert.AreEqual(enabledCdnCustomDomain.Data.CustomHttpsProvisioningState, CustomHttpsProvisioningState.Enabling);
        }
        public async Task ValidateCustomDomain()
        {
            //A CName mapping needs to be created in advance to validate custom domain.
            //In this test is "customdomainrecord.azuretest.net" maps to "testEndpoint4dotnetsdk.azureedge.net"
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

            ResourceGroupResource rg = await subscription.GetResourceGroups().GetAsync("CdnTest");

            ProfileResource cdnProfile = await rg.GetProfiles().GetAsync("testProfile");

            CdnEndpointResource cdnEndpoint = await cdnProfile.GetCdnEndpoints().GetAsync("testEndpoint4dotnetsdk");

            ValidateCustomDomainInput  validateCustomDomainInput1 = new ValidateCustomDomainInput("customdomainrecord.azuretest.net");
            ValidateCustomDomainOutput validateResult             = await cdnEndpoint.ValidateCustomDomainAsync(validateCustomDomainInput1);

            Assert.True(validateResult.CustomDomainValidated);
            ValidateCustomDomainInput validateCustomDomainInput2 = new ValidateCustomDomainInput("customdomainvirtual.azuretest.net");

            validateResult = await cdnEndpoint.ValidateCustomDomainAsync(validateCustomDomainInput2);

            Assert.False(validateResult.CustomDomainValidated);
        }