All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.azure.resourcemanager.frontdoor.models.CustomRule Maven / Gradle / Ivy

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.resourcemanager.frontdoor.models;

import com.azure.core.annotation.Fluent;
import com.azure.core.util.logging.ClientLogger;
import com.azure.json.JsonReader;
import com.azure.json.JsonSerializable;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;
import java.io.IOException;
import java.util.List;

/**
 * Defines contents of a web application rule.
 */
@Fluent
public final class CustomRule implements JsonSerializable {
    /*
     * Describes the name of the rule.
     */
    private String name;

    /*
     * Describes priority of the rule. Rules with a lower value will be evaluated before rules with a higher value.
     */
    private int priority;

    /*
     * Describes if the custom rule is in enabled or disabled state. Defaults to Enabled if not specified.
     */
    private CustomRuleEnabledState enabledState;

    /*
     * Describes type of rule.
     */
    private RuleType ruleType;

    /*
     * Time window for resetting the rate limit count. Default is 1 minute.
     */
    private Integer rateLimitDurationInMinutes;

    /*
     * Number of allowed requests per client within the time window.
     */
    private Integer rateLimitThreshold;

    /*
     * Describes the list of variables to group the rate limit requests
     */
    private List groupBy;

    /*
     * List of match conditions.
     */
    private List matchConditions;

    /*
     * Describes what action to be applied when rule matches.
     */
    private ActionType action;

    /**
     * Creates an instance of CustomRule class.
     */
    public CustomRule() {
    }

    /**
     * Get the name property: Describes the name of the rule.
     * 
     * @return the name value.
     */
    public String name() {
        return this.name;
    }

    /**
     * Set the name property: Describes the name of the rule.
     * 
     * @param name the name value to set.
     * @return the CustomRule object itself.
     */
    public CustomRule withName(String name) {
        this.name = name;
        return this;
    }

    /**
     * Get the priority property: Describes priority of the rule. Rules with a lower value will be evaluated before
     * rules with a higher value.
     * 
     * @return the priority value.
     */
    public int priority() {
        return this.priority;
    }

    /**
     * Set the priority property: Describes priority of the rule. Rules with a lower value will be evaluated before
     * rules with a higher value.
     * 
     * @param priority the priority value to set.
     * @return the CustomRule object itself.
     */
    public CustomRule withPriority(int priority) {
        this.priority = priority;
        return this;
    }

    /**
     * Get the enabledState property: Describes if the custom rule is in enabled or disabled state. Defaults to Enabled
     * if not specified.
     * 
     * @return the enabledState value.
     */
    public CustomRuleEnabledState enabledState() {
        return this.enabledState;
    }

    /**
     * Set the enabledState property: Describes if the custom rule is in enabled or disabled state. Defaults to Enabled
     * if not specified.
     * 
     * @param enabledState the enabledState value to set.
     * @return the CustomRule object itself.
     */
    public CustomRule withEnabledState(CustomRuleEnabledState enabledState) {
        this.enabledState = enabledState;
        return this;
    }

    /**
     * Get the ruleType property: Describes type of rule.
     * 
     * @return the ruleType value.
     */
    public RuleType ruleType() {
        return this.ruleType;
    }

    /**
     * Set the ruleType property: Describes type of rule.
     * 
     * @param ruleType the ruleType value to set.
     * @return the CustomRule object itself.
     */
    public CustomRule withRuleType(RuleType ruleType) {
        this.ruleType = ruleType;
        return this;
    }

    /**
     * Get the rateLimitDurationInMinutes property: Time window for resetting the rate limit count. Default is 1 minute.
     * 
     * @return the rateLimitDurationInMinutes value.
     */
    public Integer rateLimitDurationInMinutes() {
        return this.rateLimitDurationInMinutes;
    }

    /**
     * Set the rateLimitDurationInMinutes property: Time window for resetting the rate limit count. Default is 1 minute.
     * 
     * @param rateLimitDurationInMinutes the rateLimitDurationInMinutes value to set.
     * @return the CustomRule object itself.
     */
    public CustomRule withRateLimitDurationInMinutes(Integer rateLimitDurationInMinutes) {
        this.rateLimitDurationInMinutes = rateLimitDurationInMinutes;
        return this;
    }

    /**
     * Get the rateLimitThreshold property: Number of allowed requests per client within the time window.
     * 
     * @return the rateLimitThreshold value.
     */
    public Integer rateLimitThreshold() {
        return this.rateLimitThreshold;
    }

    /**
     * Set the rateLimitThreshold property: Number of allowed requests per client within the time window.
     * 
     * @param rateLimitThreshold the rateLimitThreshold value to set.
     * @return the CustomRule object itself.
     */
    public CustomRule withRateLimitThreshold(Integer rateLimitThreshold) {
        this.rateLimitThreshold = rateLimitThreshold;
        return this;
    }

    /**
     * Get the groupBy property: Describes the list of variables to group the rate limit requests.
     * 
     * @return the groupBy value.
     */
    public List groupBy() {
        return this.groupBy;
    }

    /**
     * Set the groupBy property: Describes the list of variables to group the rate limit requests.
     * 
     * @param groupBy the groupBy value to set.
     * @return the CustomRule object itself.
     */
    public CustomRule withGroupBy(List groupBy) {
        this.groupBy = groupBy;
        return this;
    }

    /**
     * Get the matchConditions property: List of match conditions.
     * 
     * @return the matchConditions value.
     */
    public List matchConditions() {
        return this.matchConditions;
    }

    /**
     * Set the matchConditions property: List of match conditions.
     * 
     * @param matchConditions the matchConditions value to set.
     * @return the CustomRule object itself.
     */
    public CustomRule withMatchConditions(List matchConditions) {
        this.matchConditions = matchConditions;
        return this;
    }

    /**
     * Get the action property: Describes what action to be applied when rule matches.
     * 
     * @return the action value.
     */
    public ActionType action() {
        return this.action;
    }

    /**
     * Set the action property: Describes what action to be applied when rule matches.
     * 
     * @param action the action value to set.
     * @return the CustomRule object itself.
     */
    public CustomRule withAction(ActionType action) {
        this.action = action;
        return this;
    }

    /**
     * Validates the instance.
     * 
     * @throws IllegalArgumentException thrown if the instance is not valid.
     */
    public void validate() {
        if (ruleType() == null) {
            throw LOGGER.atError()
                .log(new IllegalArgumentException("Missing required property ruleType in model CustomRule"));
        }
        if (groupBy() != null) {
            groupBy().forEach(e -> e.validate());
        }
        if (matchConditions() == null) {
            throw LOGGER.atError()
                .log(new IllegalArgumentException("Missing required property matchConditions in model CustomRule"));
        } else {
            matchConditions().forEach(e -> e.validate());
        }
        if (action() == null) {
            throw LOGGER.atError()
                .log(new IllegalArgumentException("Missing required property action in model CustomRule"));
        }
    }

    private static final ClientLogger LOGGER = new ClientLogger(CustomRule.class);

    /**
     * {@inheritDoc}
     */
    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeIntField("priority", this.priority);
        jsonWriter.writeStringField("ruleType", this.ruleType == null ? null : this.ruleType.toString());
        jsonWriter.writeArrayField("matchConditions", this.matchConditions,
            (writer, element) -> writer.writeJson(element));
        jsonWriter.writeStringField("action", this.action == null ? null : this.action.toString());
        jsonWriter.writeStringField("name", this.name);
        jsonWriter.writeStringField("enabledState", this.enabledState == null ? null : this.enabledState.toString());
        jsonWriter.writeNumberField("rateLimitDurationInMinutes", this.rateLimitDurationInMinutes);
        jsonWriter.writeNumberField("rateLimitThreshold", this.rateLimitThreshold);
        jsonWriter.writeArrayField("groupBy", this.groupBy, (writer, element) -> writer.writeJson(element));
        return jsonWriter.writeEndObject();
    }

    /**
     * Reads an instance of CustomRule from the JsonReader.
     * 
     * @param jsonReader The JsonReader being read.
     * @return An instance of CustomRule if the JsonReader was pointing to an instance of it, or null if it was pointing
     * to JSON null.
     * @throws IllegalStateException If the deserialized JSON object was missing any required properties.
     * @throws IOException If an error occurs while reading the CustomRule.
     */
    public static CustomRule fromJson(JsonReader jsonReader) throws IOException {
        return jsonReader.readObject(reader -> {
            CustomRule deserializedCustomRule = new CustomRule();
            while (reader.nextToken() != JsonToken.END_OBJECT) {
                String fieldName = reader.getFieldName();
                reader.nextToken();

                if ("priority".equals(fieldName)) {
                    deserializedCustomRule.priority = reader.getInt();
                } else if ("ruleType".equals(fieldName)) {
                    deserializedCustomRule.ruleType = RuleType.fromString(reader.getString());
                } else if ("matchConditions".equals(fieldName)) {
                    List matchConditions
                        = reader.readArray(reader1 -> MatchCondition.fromJson(reader1));
                    deserializedCustomRule.matchConditions = matchConditions;
                } else if ("action".equals(fieldName)) {
                    deserializedCustomRule.action = ActionType.fromString(reader.getString());
                } else if ("name".equals(fieldName)) {
                    deserializedCustomRule.name = reader.getString();
                } else if ("enabledState".equals(fieldName)) {
                    deserializedCustomRule.enabledState = CustomRuleEnabledState.fromString(reader.getString());
                } else if ("rateLimitDurationInMinutes".equals(fieldName)) {
                    deserializedCustomRule.rateLimitDurationInMinutes = reader.getNullable(JsonReader::getInt);
                } else if ("rateLimitThreshold".equals(fieldName)) {
                    deserializedCustomRule.rateLimitThreshold = reader.getNullable(JsonReader::getInt);
                } else if ("groupBy".equals(fieldName)) {
                    List groupBy = reader.readArray(reader1 -> GroupByVariable.fromJson(reader1));
                    deserializedCustomRule.groupBy = groupBy;
                } else {
                    reader.skipChildren();
                }
            }

            return deserializedCustomRule;
        });
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy