protected async Task <AfdRule> CreateAfdRule(AfdRuleSet ruleSet, string ruleName)
        {
            AfdRuleData                     input = ResourceDataHelper.CreateAfdRuleData();
            DeliveryRuleCondition           deliveryRuleCondition = ResourceDataHelper.CreateDeliveryRuleCondition();
            DeliveryRuleActionAutoGenerated deliveryRuleAction    = ResourceDataHelper.CreateDeliveryRuleOperation();

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

            return(lro.Value);
        }
Exemple #2
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);
        }
Exemple #3
0
        internal static FrontDoorRuleData DeserializeFrontDoorRuleData(JsonElement element)
        {
            ResourceIdentifier id          = default;
            string             name        = default;
            ResourceType       type        = default;
            SystemData         systemData  = default;
            Optional <string>  ruleSetName = default;
            Optional <int>     order       = default;
            Optional <IList <DeliveryRuleCondition> > conditions = default;
            Optional <IList <DeliveryRuleAction> >    actions    = default;
            Optional <MatchProcessingBehavior>        matchProcessingBehavior = default;
            Optional <FrontDoorProvisioningState>     provisioningState       = default;
            Optional <FrontDoorDeploymentStatus>      deploymentStatus        = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("id"))
                {
                    id = new ResourceIdentifier(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("name"))
                {
                    name = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("type"))
                {
                    type = new ResourceType(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("systemData"))
                {
                    systemData = JsonSerializer.Deserialize <SystemData>(property.Value.ToString());
                    continue;
                }
                if (property.NameEquals("properties"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    foreach (var property0 in property.Value.EnumerateObject())
                    {
                        if (property0.NameEquals("ruleSetName"))
                        {
                            ruleSetName = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("order"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            order = property0.Value.GetInt32();
                            continue;
                        }
                        if (property0.NameEquals("conditions"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            List <DeliveryRuleCondition> array = new List <DeliveryRuleCondition>();
                            foreach (var item in property0.Value.EnumerateArray())
                            {
                                array.Add(DeliveryRuleCondition.DeserializeDeliveryRuleCondition(item));
                            }
                            conditions = array;
                            continue;
                        }
                        if (property0.NameEquals("actions"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            List <DeliveryRuleAction> array = new List <DeliveryRuleAction>();
                            foreach (var item in property0.Value.EnumerateArray())
                            {
                                array.Add(DeliveryRuleAction.DeserializeDeliveryRuleAction(item));
                            }
                            actions = array;
                            continue;
                        }
                        if (property0.NameEquals("matchProcessingBehavior"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            matchProcessingBehavior = new MatchProcessingBehavior(property0.Value.GetString());
                            continue;
                        }
                        if (property0.NameEquals("provisioningState"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            provisioningState = new FrontDoorProvisioningState(property0.Value.GetString());
                            continue;
                        }
                        if (property0.NameEquals("deploymentStatus"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            deploymentStatus = new FrontDoorDeploymentStatus(property0.Value.GetString());
                            continue;
                        }
                    }
                    continue;
                }
            }
            return(new FrontDoorRuleData(id, name, type, systemData, ruleSetName.Value, Optional.ToNullable(order), Optional.ToList(conditions), Optional.ToList(actions), Optional.ToNullable(matchProcessingBehavior), Optional.ToNullable(provisioningState), Optional.ToNullable(deploymentStatus)));
        }
Exemple #4
0
 public static PSDeliveryRuleCondition ToPsDeliveryRuleCondition(this DeliveryRuleCondition deliveryRuleCondition)
 {
     if (deliveryRuleCondition is DeliveryRuleRemoteAddressCondition deliveryRuleRemoteAddressCondition)
     {
         return(new PSDeliveryRuleCondition
         {
             MatchVariable = "RemoteAddress",
             Operator = deliveryRuleRemoteAddressCondition.Parameters.OperatorProperty,
             NegateCondition = deliveryRuleRemoteAddressCondition.Parameters.NegateCondition,
             MatchValue = deliveryRuleRemoteAddressCondition.Parameters.MatchValues,
             Transfroms = deliveryRuleRemoteAddressCondition.Parameters.Transforms
         });
     }
     else if (deliveryRuleCondition is DeliveryRuleRequestMethodCondition deliveryRuleRequestMethodCondition)
     {
         return(new PSDeliveryRuleCondition
         {
             MatchVariable = "RequestMethod",
             Operator = "Equal",
             NegateCondition = deliveryRuleRequestMethodCondition.Parameters.NegateCondition,
             MatchValue = deliveryRuleRequestMethodCondition.Parameters.MatchValues
         });
     }
     else if (deliveryRuleCondition is DeliveryRuleQueryStringCondition deliveryRuleQueryStringCondition)
     {
         return(new PSDeliveryRuleCondition
         {
             MatchVariable = "QueryString",
             Operator = deliveryRuleQueryStringCondition.Parameters.OperatorProperty,
             NegateCondition = deliveryRuleQueryStringCondition.Parameters.NegateCondition,
             MatchValue = deliveryRuleQueryStringCondition.Parameters.MatchValues,
             Transfroms = deliveryRuleQueryStringCondition.Parameters.Transforms
         });
     }
     else if (deliveryRuleCondition is DeliveryRulePostArgsCondition deliveryRulePostArgsCondition)
     {
         return(new PSDeliveryRuleCondition
         {
             MatchVariable = "PostArgs",
             Operator = deliveryRulePostArgsCondition.Parameters.OperatorProperty,
             Selector = deliveryRulePostArgsCondition.Parameters.Selector,
             NegateCondition = deliveryRulePostArgsCondition.Parameters.NegateCondition,
             MatchValue = deliveryRulePostArgsCondition.Parameters.MatchValues,
             Transfroms = deliveryRulePostArgsCondition.Parameters.Transforms
         });
     }
     else if (deliveryRuleCondition is DeliveryRuleRemoteAddressCondition deliveryRuleRequestUriCondition)
     {
         return(new PSDeliveryRuleCondition
         {
             MatchVariable = "RequestUri",
             Operator = deliveryRuleRequestUriCondition.Parameters.OperatorProperty,
             NegateCondition = deliveryRuleRequestUriCondition.Parameters.NegateCondition,
             MatchValue = deliveryRuleRequestUriCondition.Parameters.MatchValues,
             Transfroms = deliveryRuleRequestUriCondition.Parameters.Transforms
         });
     }
     else if (deliveryRuleCondition is DeliveryRuleRequestHeaderCondition deliveryRuleRequestHeaderCondition)
     {
         return(new PSDeliveryRuleCondition
         {
             MatchVariable = "RequestHeader",
             Operator = deliveryRuleRequestHeaderCondition.Parameters.OperatorProperty,
             NegateCondition = deliveryRuleRequestHeaderCondition.Parameters.NegateCondition,
             Selector = deliveryRuleRequestHeaderCondition.Parameters.Selector,
             MatchValue = deliveryRuleRequestHeaderCondition.Parameters.MatchValues,
             Transfroms = deliveryRuleRequestHeaderCondition.Parameters.Transforms
         });
     }
     else if (deliveryRuleCondition is DeliveryRuleRequestBodyCondition deliveryRuleRequestBodyCondition)
     {
         return(new PSDeliveryRuleCondition
         {
             MatchVariable = "RequestBody",
             Operator = deliveryRuleRequestBodyCondition.Parameters.OperatorProperty,
             NegateCondition = deliveryRuleRequestBodyCondition.Parameters.NegateCondition,
             MatchValue = deliveryRuleRequestBodyCondition.Parameters.MatchValues,
             Transfroms = deliveryRuleRequestBodyCondition.Parameters.Transforms
         });
     }
     else if (deliveryRuleCondition is DeliveryRuleRequestSchemeCondition deliveryRuleRequestSchemeCondition)
     {
         return(new PSDeliveryRuleCondition
         {
             MatchVariable = "RequestScheme",
             NegateCondition = deliveryRuleRequestSchemeCondition.Parameters.NegateCondition,
             MatchValue = deliveryRuleRequestSchemeCondition.Parameters.MatchValues
         });
     }
     else if (deliveryRuleCondition is DeliveryRuleUrlPathCondition deliveryRuleUrlPathCondition)
     {
         return(new PSDeliveryRuleCondition
         {
             MatchVariable = "UrlPath",
             Operator = deliveryRuleUrlPathCondition.Parameters.OperatorProperty,
             NegateCondition = deliveryRuleUrlPathCondition.Parameters.NegateCondition,
             MatchValue = deliveryRuleUrlPathCondition.Parameters.MatchValues,
             Transfroms = deliveryRuleUrlPathCondition.Parameters.Transforms
         });
     }
     else if (deliveryRuleCondition is DeliveryRuleUrlFileExtensionCondition deliveryRuleUrlFileExtensionCondition)
     {
         return(new PSDeliveryRuleCondition
         {
             MatchVariable = "UrlFileExtension",
             Operator = deliveryRuleUrlFileExtensionCondition.Parameters.OperatorProperty,
             NegateCondition = deliveryRuleUrlFileExtensionCondition.Parameters.NegateCondition,
             MatchValue = deliveryRuleUrlFileExtensionCondition.Parameters.MatchValues,
             Transfroms = deliveryRuleUrlFileExtensionCondition.Parameters.Transforms
         });
     }
     else if (deliveryRuleCondition is DeliveryRuleUrlFileNameCondition deliveryRuleUrlFileNameCondition)
     {
         return(new PSDeliveryRuleCondition
         {
             MatchVariable = "UrlFileName",
             Operator = deliveryRuleUrlFileNameCondition.Parameters.OperatorProperty,
             NegateCondition = deliveryRuleUrlFileNameCondition.Parameters.NegateCondition,
             MatchValue = deliveryRuleUrlFileNameCondition.Parameters.MatchValues,
             Transfroms = deliveryRuleUrlFileNameCondition.Parameters.Transforms
         });
     }
     else if (deliveryRuleCondition is DeliveryRuleIsDeviceCondition deliveryRuleIsDeviceCondition)
     {
         return(new PSDeliveryRuleCondition
         {
             MatchVariable = "IsDevice",
             NegateCondition = deliveryRuleIsDeviceCondition.Parameters.NegateCondition,
             MatchValue = deliveryRuleIsDeviceCondition.Parameters.MatchValues
         });
     }
     else
     {
         return(new PSDeliveryRuleCondition());
     }
 }