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

com.azure.resourcemanager.security.models.AllowlistCustomAlertRule Maven / Gradle / Ivy

Go to download

This package contains Microsoft Azure SDK for Security Management SDK. For documentation on how to use this package, please see https://aka.ms/azsdk/java/mgmt. API spec for Microsoft.Security (Azure Security Center) resource provider. Package tag package-composite-v3.

There is a newer version: 1.0.0
Show newest version
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.resourcemanager.security.models;

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

/**
 * A custom alert rule that checks if a value (depends on the custom alert type) is allowed.
 */
@Fluent
public class AllowlistCustomAlertRule extends ListCustomAlertRule {
    /*
     * The type of the custom alert rule.
     */
    private String ruleType = "AllowlistCustomAlertRule";

    /*
     * The values to allow. The format of the values depends on the rule type.
     */
    private List allowlistValues;

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

    /**
     * Get the ruleType property: The type of the custom alert rule.
     * 
     * @return the ruleType value.
     */
    @Override
    public String ruleType() {
        return this.ruleType;
    }

    /**
     * Get the allowlistValues property: The values to allow. The format of the values depends on the rule type.
     * 
     * @return the allowlistValues value.
     */
    public List allowlistValues() {
        return this.allowlistValues;
    }

    /**
     * Set the allowlistValues property: The values to allow. The format of the values depends on the rule type.
     * 
     * @param allowlistValues the allowlistValues value to set.
     * @return the AllowlistCustomAlertRule object itself.
     */
    public AllowlistCustomAlertRule withAllowlistValues(List allowlistValues) {
        this.allowlistValues = allowlistValues;
        return this;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public AllowlistCustomAlertRule withIsEnabled(boolean isEnabled) {
        super.withIsEnabled(isEnabled);
        return this;
    }

    /**
     * Validates the instance.
     * 
     * @throws IllegalArgumentException thrown if the instance is not valid.
     */
    @Override
    public void validate() {
        if (allowlistValues() == null) {
            throw LOGGER.atError()
                .log(new IllegalArgumentException(
                    "Missing required property allowlistValues in model AllowlistCustomAlertRule"));
        }
    }

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

    /**
     * {@inheritDoc}
     */
    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeBooleanField("isEnabled", isEnabled());
        jsonWriter.writeArrayField("allowlistValues", this.allowlistValues,
            (writer, element) -> writer.writeString(element));
        jsonWriter.writeStringField("ruleType", this.ruleType);
        return jsonWriter.writeEndObject();
    }

    /**
     * Reads an instance of AllowlistCustomAlertRule from the JsonReader.
     * 
     * @param jsonReader The JsonReader being read.
     * @return An instance of AllowlistCustomAlertRule 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 AllowlistCustomAlertRule.
     */
    public static AllowlistCustomAlertRule fromJson(JsonReader jsonReader) throws IOException {
        return jsonReader.readObject(reader -> {
            String discriminatorValue = null;
            try (JsonReader readerToUse = reader.bufferObject()) {
                readerToUse.nextToken(); // Prepare for reading
                while (readerToUse.nextToken() != JsonToken.END_OBJECT) {
                    String fieldName = readerToUse.getFieldName();
                    readerToUse.nextToken();
                    if ("ruleType".equals(fieldName)) {
                        discriminatorValue = readerToUse.getString();
                        break;
                    } else {
                        readerToUse.skipChildren();
                    }
                }
                // Use the discriminator value to determine which subtype should be deserialized.
                if ("ConnectionToIpNotAllowed".equals(discriminatorValue)) {
                    return ConnectionToIpNotAllowed.fromJson(readerToUse.reset());
                } else if ("ConnectionFromIpNotAllowed".equals(discriminatorValue)) {
                    return ConnectionFromIpNotAllowed.fromJson(readerToUse.reset());
                } else if ("LocalUserNotAllowed".equals(discriminatorValue)) {
                    return LocalUserNotAllowed.fromJson(readerToUse.reset());
                } else if ("ProcessNotAllowed".equals(discriminatorValue)) {
                    return ProcessNotAllowed.fromJson(readerToUse.reset());
                } else {
                    return fromJsonKnownDiscriminator(readerToUse.reset());
                }
            }
        });
    }

    static AllowlistCustomAlertRule fromJsonKnownDiscriminator(JsonReader jsonReader) throws IOException {
        return jsonReader.readObject(reader -> {
            AllowlistCustomAlertRule deserializedAllowlistCustomAlertRule = new AllowlistCustomAlertRule();
            while (reader.nextToken() != JsonToken.END_OBJECT) {
                String fieldName = reader.getFieldName();
                reader.nextToken();

                if ("isEnabled".equals(fieldName)) {
                    deserializedAllowlistCustomAlertRule.withIsEnabled(reader.getBoolean());
                } else if ("displayName".equals(fieldName)) {
                    deserializedAllowlistCustomAlertRule.withDisplayName(reader.getString());
                } else if ("description".equals(fieldName)) {
                    deserializedAllowlistCustomAlertRule.withDescription(reader.getString());
                } else if ("valueType".equals(fieldName)) {
                    deserializedAllowlistCustomAlertRule.withValueType(ValueType.fromString(reader.getString()));
                } else if ("allowlistValues".equals(fieldName)) {
                    List allowlistValues = reader.readArray(reader1 -> reader1.getString());
                    deserializedAllowlistCustomAlertRule.allowlistValues = allowlistValues;
                } else if ("ruleType".equals(fieldName)) {
                    deserializedAllowlistCustomAlertRule.ruleType = reader.getString();
                } else {
                    reader.skipChildren();
                }
            }

            return deserializedAllowlistCustomAlertRule;
        });
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy