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

com.azure.resourcemanager.security.fluent.models.JitNetworkAccessRequestInner 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.fluent.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 com.azure.resourcemanager.security.models.JitNetworkAccessRequestVirtualMachine;
import java.io.IOException;
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

/**
 * The JitNetworkAccessRequest model.
 */
@Fluent
public final class JitNetworkAccessRequestInner implements JsonSerializable {
    /*
     * The virtualMachines property.
     */
    private List virtualMachines;

    /*
     * The start time of the request in UTC
     */
    private OffsetDateTime startTimeUtc;

    /*
     * The identity of the person who made the request
     */
    private String requestor;

    /*
     * The justification for making the initiate request
     */
    private String justification;

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

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

    /**
     * Set the virtualMachines property: The virtualMachines property.
     * 
     * @param virtualMachines the virtualMachines value to set.
     * @return the JitNetworkAccessRequestInner object itself.
     */
    public JitNetworkAccessRequestInner
        withVirtualMachines(List virtualMachines) {
        this.virtualMachines = virtualMachines;
        return this;
    }

    /**
     * Get the startTimeUtc property: The start time of the request in UTC.
     * 
     * @return the startTimeUtc value.
     */
    public OffsetDateTime startTimeUtc() {
        return this.startTimeUtc;
    }

    /**
     * Set the startTimeUtc property: The start time of the request in UTC.
     * 
     * @param startTimeUtc the startTimeUtc value to set.
     * @return the JitNetworkAccessRequestInner object itself.
     */
    public JitNetworkAccessRequestInner withStartTimeUtc(OffsetDateTime startTimeUtc) {
        this.startTimeUtc = startTimeUtc;
        return this;
    }

    /**
     * Get the requestor property: The identity of the person who made the request.
     * 
     * @return the requestor value.
     */
    public String requestor() {
        return this.requestor;
    }

    /**
     * Set the requestor property: The identity of the person who made the request.
     * 
     * @param requestor the requestor value to set.
     * @return the JitNetworkAccessRequestInner object itself.
     */
    public JitNetworkAccessRequestInner withRequestor(String requestor) {
        this.requestor = requestor;
        return this;
    }

    /**
     * Get the justification property: The justification for making the initiate request.
     * 
     * @return the justification value.
     */
    public String justification() {
        return this.justification;
    }

    /**
     * Set the justification property: The justification for making the initiate request.
     * 
     * @param justification the justification value to set.
     * @return the JitNetworkAccessRequestInner object itself.
     */
    public JitNetworkAccessRequestInner withJustification(String justification) {
        this.justification = justification;
        return this;
    }

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

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

    /**
     * {@inheritDoc}
     */
    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeArrayField("virtualMachines", this.virtualMachines,
            (writer, element) -> writer.writeJson(element));
        jsonWriter.writeStringField("startTimeUtc",
            this.startTimeUtc == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(this.startTimeUtc));
        jsonWriter.writeStringField("requestor", this.requestor);
        jsonWriter.writeStringField("justification", this.justification);
        return jsonWriter.writeEndObject();
    }

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

                if ("virtualMachines".equals(fieldName)) {
                    List virtualMachines
                        = reader.readArray(reader1 -> JitNetworkAccessRequestVirtualMachine.fromJson(reader1));
                    deserializedJitNetworkAccessRequestInner.virtualMachines = virtualMachines;
                } else if ("startTimeUtc".equals(fieldName)) {
                    deserializedJitNetworkAccessRequestInner.startTimeUtc = reader
                        .getNullable(nonNullReader -> CoreUtils.parseBestOffsetDateTime(nonNullReader.getString()));
                } else if ("requestor".equals(fieldName)) {
                    deserializedJitNetworkAccessRequestInner.requestor = reader.getString();
                } else if ("justification".equals(fieldName)) {
                    deserializedJitNetworkAccessRequestInner.justification = reader.getString();
                } else {
                    reader.skipChildren();
                }
            }

            return deserializedJitNetworkAccessRequestInner;
        });
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy