Beispiel #1
0
        public async Task UpdateAfdRules()
        {
            #region Snippet:Managing_AfdRules_UpdateAnAzureFrontDoorRule
            // First we need to get the azure front door rule collection from the specific rule set
            ProfileResource AfdProfileResource = await resourceGroup.GetProfiles().GetAsync("myAfdProfile");

            FrontDoorRuleSetResource ruleSet = await AfdProfileResource.GetFrontDoorRuleSets().GetAsync("myAfdRuleSet");

            FrontDoorRuleCollection ruleCollection = ruleSet.GetFrontDoorRules();
            // Now we can get the rule with GetAsync()
            FrontDoorRuleResource rule = await ruleCollection.GetAsync("myAfdRule");

            // With UpdateAsync(), we can update the rule
            FrontDoorRulePatch input = new FrontDoorRulePatch
            {
                Order = 2
            };
            input.Conditions.Add(new DeliveryRuleRequestUriCondition(new RequestUriMatchCondition(RequestUriMatchConditionType.RequestUriCondition, RequestUriOperator.Any)));
            input.Actions.Add(new DeliveryRuleCacheExpirationAction(new CacheExpirationActionProperties(CacheExpirationActionType.CacheExpirationAction, CacheBehaviorSetting.Override, CacheLevel.All)
            {
                CacheDuration = new TimeSpan(0, 0, 30)
            }));
            ArmOperation <FrontDoorRuleResource> lro = await rule.UpdateAsync(WaitUntil.Completed, input);

            rule = lro.Value;
            #endregion Snippet:Managing_AfdRules_UpdateAnAzureFrontDoorRule
        }
Beispiel #2
0
        public async Task CreateAfdRules()
        {
            #region Snippet:Managing_AfdRules_CreateAnAzureFrontDoorRule
            // Create a new azure front door profile
            string AfdProfileName = "myAfdProfile";
            var    input1         = new ProfileData("Global", new CdnSku {
                Name = CdnSkuName.StandardAzureFrontDoor
            });
            ArmOperation <ProfileResource> lro1 = await resourceGroup.GetProfiles().CreateOrUpdateAsync(WaitUntil.Completed, AfdProfileName, input1);

            ProfileResource AfdProfileResource = lro1.Value;
            // Get the rule set collection from the specific azure front door ProfileResource and create a rule set
            string ruleSetName = "myAfdRuleSet";
            ArmOperation <FrontDoorRuleSetResource> lro2 = await AfdProfileResource.GetFrontDoorRuleSets().CreateOrUpdateAsync(WaitUntil.Completed, ruleSetName);

            FrontDoorRuleSetResource ruleSet = lro2.Value;
            // Get the rule collection from the specific rule set and create a rule
            string            ruleName = "myAfdRule";
            FrontDoorRuleData input3   = new FrontDoorRuleData
            {
                Order = 1
            };
            input3.Conditions.Add(new DeliveryRuleRequestUriCondition(new RequestUriMatchCondition(RequestUriMatchConditionType.RequestUriCondition, RequestUriOperator.Any)));
            input3.Actions.Add(new DeliveryRuleCacheExpirationAction(new CacheExpirationActionProperties(CacheExpirationActionType.CacheExpirationAction, CacheBehaviorSetting.Override, CacheLevel.All)
            {
                CacheDuration = new TimeSpan(0, 0, 20)
            }));
            ArmOperation <FrontDoorRuleResource> lro3 = await ruleSet.GetFrontDoorRules().CreateOrUpdateAsync(WaitUntil.Completed, ruleName, input3);

            FrontDoorRuleResource rule = lro3.Value;
            #endregion Snippet:Managing_AfdRules_CreateAnAzureFrontDoorRule
        }
Beispiel #3
0
        public async Task CreateOrUpdate()
        {
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

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

            string          afdProfileName     = Recording.GenerateAssetName("AFDProfile-");
            ProfileResource afdProfileResource = await CreateAfdProfile(rg, afdProfileName, CdnSkuName.StandardAzureFrontDoor);

            string afdRuleSetName = Recording.GenerateAssetName("AFDRuleSet");
            FrontDoorRuleSetResource afdRuleSet = await CreateAfdRuleSet(afdProfileResource, afdRuleSetName);

            string afdRuleName            = Recording.GenerateAssetName("AFDRule");
            FrontDoorRuleResource afdRule = await CreateAfdRule(afdRuleSet, afdRuleName);

            Assert.AreEqual(afdRuleName, afdRule.Data.Name);
            Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await afdRuleSet.GetFrontDoorRules().CreateOrUpdateAsync(WaitUntil.Completed, null, afdRule.Data));
            Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await afdRuleSet.GetFrontDoorRules().CreateOrUpdateAsync(WaitUntil.Completed, afdRuleName, null));
        }
Beispiel #4
0
        public async Task Get()
        {
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

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

            string          afdProfileName     = Recording.GenerateAssetName("AFDProfile-");
            ProfileResource afdProfileResource = await CreateAfdProfile(rg, afdProfileName, CdnSkuName.StandardAzureFrontDoor);

            string afdRuleSetName = Recording.GenerateAssetName("AFDRuleSet");
            FrontDoorRuleSetResource afdRuleSet = await CreateAfdRuleSet(afdProfileResource, afdRuleSetName);

            string afdRuleName            = Recording.GenerateAssetName("AFDRule");
            FrontDoorRuleResource afdRule = await CreateAfdRule(afdRuleSet, afdRuleName);

            FrontDoorRuleResource getAfdRule = await afdRuleSet.GetFrontDoorRules().GetAsync(afdRuleName);

            ResourceDataHelper.AssertValidAfdRule(afdRule, getAfdRule);
            Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await afdRuleSet.GetFrontDoorRules().GetAsync(null));
        }
Beispiel #5
0
        protected async Task <FrontDoorRuleResource> CreateAfdRule(FrontDoorRuleSetResource ruleSet, string ruleName)
        {
            FrontDoorRuleData     input = ResourceDataHelper.CreateAfdRuleData();
            DeliveryRuleCondition deliveryRuleCondition = ResourceDataHelper.CreateDeliveryRuleCondition();
            DeliveryRuleAction    deliveryRuleAction    = ResourceDataHelper.CreateDeliveryRuleOperation();

            input.Conditions.Add(deliveryRuleCondition);
            input.Actions.Add(deliveryRuleAction);
            var lro = await ruleSet.GetFrontDoorRules().CreateOrUpdateAsync(WaitUntil.Completed, ruleName, input);

            return(lro.Value);
        }
Beispiel #6
0
        public async Task ListAfdRules()
        {
            #region Snippet:Managing_AfdRules_ListAllAzureFrontDoorRules
            // First we need to get the azure front door rule collection from the specific rule set
            ProfileResource AfdProfileResource = await resourceGroup.GetProfiles().GetAsync("myAfdProfile");

            FrontDoorRuleSetResource ruleSet = await AfdProfileResource.GetFrontDoorRuleSets().GetAsync("myAfdRuleSet");

            FrontDoorRuleCollection ruleCollection = ruleSet.GetFrontDoorRules();
            // With GetAllAsync(), we can get a list of the rule in the collection
            AsyncPageable <FrontDoorRuleResource> response = ruleCollection.GetAllAsync();
            await foreach (FrontDoorRuleResource rule in response)
            {
                Console.WriteLine(rule.Data.Name);
            }
            #endregion Snippet:Managing_AfdRules_ListAllAzureFrontDoorRules
        }
Beispiel #7
0
        public async Task DeleteAfdRules()
        {
            #region Snippet:Managing_AfdRules_DeleteAnAzureFrontDoorRule
            // First we need to get the azure front door rule collection from the specific rule set
            ProfileResource AfdProfileResource = await resourceGroup.GetProfiles().GetAsync("myAfdProfile");

            FrontDoorRuleSetResource ruleSet = await AfdProfileResource.GetFrontDoorRuleSets().GetAsync("myAfdRuleSet");

            FrontDoorRuleCollection ruleCollection = ruleSet.GetFrontDoorRules();
            // Now we can get the rule with GetAsync()
            FrontDoorRuleResource rule = await ruleCollection.GetAsync("myAfdRule");

            // With DeleteAsync(), we can delete the rule
            await rule.DeleteAsync(WaitUntil.Completed);

            #endregion Snippet:Managing_AfdRules_DeleteAnAzureFrontDoorRule
        }
Beispiel #8
0
        public async Task List()
        {
            SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync();

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

            string          afdProfileName     = Recording.GenerateAssetName("AFDProfile-");
            ProfileResource afdProfileResource = await CreateAfdProfile(rg, afdProfileName, CdnSkuName.StandardAzureFrontDoor);

            string afdRuleSetName = Recording.GenerateAssetName("AFDRuleSet");
            FrontDoorRuleSetResource afdRuleSet = await CreateAfdRuleSet(afdProfileResource, afdRuleSetName);

            string afdRuleName = Recording.GenerateAssetName("AFDRule");

            _ = await CreateAfdRule(afdRuleSet, afdRuleName);

            int count = 0;

            await foreach (var tempRule in afdRuleSet.GetFrontDoorRules().GetAllAsync())
            {
                count++;
            }
            Assert.AreEqual(count, 1);
        }