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

com.azure.resourcemanager.security.models.JitNetworkAccessPolicyInitiatePort 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.security.models;

import com.azure.core.annotation.Fluent;
import com.azure.core.util.CoreUtils;
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.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;

/**
 * The JitNetworkAccessPolicyInitiatePort model.
 */
@Fluent
public final class JitNetworkAccessPolicyInitiatePort implements JsonSerializable {
    /*
     * The number property.
     */
    private int number;

    /*
     * Source of the allowed traffic. If omitted, the request will be for the source IP address of the initiate request.
     */
    private String allowedSourceAddressPrefix;

    /*
     * The time to close the request in UTC
     */
    private OffsetDateTime endTimeUtc;

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

    /**
     * Get the number property: The number property.
     * 
     * @return the number value.
     */
    public int number() {
        return this.number;
    }

    /**
     * Set the number property: The number property.
     * 
     * @param number the number value to set.
     * @return the JitNetworkAccessPolicyInitiatePort object itself.
     */
    public JitNetworkAccessPolicyInitiatePort withNumber(int number) {
        this.number = number;
        return this;
    }

    /**
     * Get the allowedSourceAddressPrefix property: Source of the allowed traffic. If omitted, the request will be for
     * the source IP address of the initiate request.
     * 
     * @return the allowedSourceAddressPrefix value.
     */
    public String allowedSourceAddressPrefix() {
        return this.allowedSourceAddressPrefix;
    }

    /**
     * Set the allowedSourceAddressPrefix property: Source of the allowed traffic. If omitted, the request will be for
     * the source IP address of the initiate request.
     * 
     * @param allowedSourceAddressPrefix the allowedSourceAddressPrefix value to set.
     * @return the JitNetworkAccessPolicyInitiatePort object itself.
     */
    public JitNetworkAccessPolicyInitiatePort withAllowedSourceAddressPrefix(String allowedSourceAddressPrefix) {
        this.allowedSourceAddressPrefix = allowedSourceAddressPrefix;
        return this;
    }

    /**
     * Get the endTimeUtc property: The time to close the request in UTC.
     * 
     * @return the endTimeUtc value.
     */
    public OffsetDateTime endTimeUtc() {
        return this.endTimeUtc;
    }

    /**
     * Set the endTimeUtc property: The time to close the request in UTC.
     * 
     * @param endTimeUtc the endTimeUtc value to set.
     * @return the JitNetworkAccessPolicyInitiatePort object itself.
     */
    public JitNetworkAccessPolicyInitiatePort withEndTimeUtc(OffsetDateTime endTimeUtc) {
        this.endTimeUtc = endTimeUtc;
        return this;
    }

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

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

    /**
     * {@inheritDoc}
     */
    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeIntField("number", this.number);
        jsonWriter.writeStringField("endTimeUtc",
            this.endTimeUtc == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(this.endTimeUtc));
        jsonWriter.writeStringField("allowedSourceAddressPrefix", this.allowedSourceAddressPrefix);
        return jsonWriter.writeEndObject();
    }

    /**
     * Reads an instance of JitNetworkAccessPolicyInitiatePort from the JsonReader.
     * 
     * @param jsonReader The JsonReader being read.
     * @return An instance of JitNetworkAccessPolicyInitiatePort 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 JitNetworkAccessPolicyInitiatePort.
     */
    public static JitNetworkAccessPolicyInitiatePort fromJson(JsonReader jsonReader) throws IOException {
        return jsonReader.readObject(reader -> {
            JitNetworkAccessPolicyInitiatePort deserializedJitNetworkAccessPolicyInitiatePort
                = new JitNetworkAccessPolicyInitiatePort();
            while (reader.nextToken() != JsonToken.END_OBJECT) {
                String fieldName = reader.getFieldName();
                reader.nextToken();

                if ("number".equals(fieldName)) {
                    deserializedJitNetworkAccessPolicyInitiatePort.number = reader.getInt();
                } else if ("endTimeUtc".equals(fieldName)) {
                    deserializedJitNetworkAccessPolicyInitiatePort.endTimeUtc = reader
                        .getNullable(nonNullReader -> CoreUtils.parseBestOffsetDateTime(nonNullReader.getString()));
                } else if ("allowedSourceAddressPrefix".equals(fieldName)) {
                    deserializedJitNetworkAccessPolicyInitiatePort.allowedSourceAddressPrefix = reader.getString();
                } else {
                    reader.skipChildren();
                }
            }

            return deserializedJitNetworkAccessPolicyInitiatePort;
        });
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy