com.azure.resourcemanager.security.models.JitNetworkAccessPortRule 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.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;
/**
* The JitNetworkAccessPortRule model.
*/
@Fluent
public final class JitNetworkAccessPortRule implements JsonSerializable {
/*
* The number property.
*/
private int number;
/*
* The protocol property.
*/
private Protocol protocol;
/*
* Mutually exclusive with the "allowedSourceAddressPrefixes" parameter. Should be an IP address or CIDR, for
* example "192.168.0.3" or "192.168.0.0/16".
*/
private String allowedSourceAddressPrefix;
/*
* Mutually exclusive with the "allowedSourceAddressPrefix" parameter.
*/
private List allowedSourceAddressPrefixes;
/*
* Maximum duration requests can be made for. In ISO 8601 duration format. Minimum 5 minutes, maximum 1 day
*/
private String maxRequestAccessDuration;
/**
* Creates an instance of JitNetworkAccessPortRule class.
*/
public JitNetworkAccessPortRule() {
}
/**
* 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 JitNetworkAccessPortRule object itself.
*/
public JitNetworkAccessPortRule withNumber(int number) {
this.number = number;
return this;
}
/**
* Get the protocol property: The protocol property.
*
* @return the protocol value.
*/
public Protocol protocol() {
return this.protocol;
}
/**
* Set the protocol property: The protocol property.
*
* @param protocol the protocol value to set.
* @return the JitNetworkAccessPortRule object itself.
*/
public JitNetworkAccessPortRule withProtocol(Protocol protocol) {
this.protocol = protocol;
return this;
}
/**
* Get the allowedSourceAddressPrefix property: Mutually exclusive with the "allowedSourceAddressPrefixes"
* parameter. Should be an IP address or CIDR, for example "192.168.0.3" or "192.168.0.0/16".
*
* @return the allowedSourceAddressPrefix value.
*/
public String allowedSourceAddressPrefix() {
return this.allowedSourceAddressPrefix;
}
/**
* Set the allowedSourceAddressPrefix property: Mutually exclusive with the "allowedSourceAddressPrefixes"
* parameter. Should be an IP address or CIDR, for example "192.168.0.3" or "192.168.0.0/16".
*
* @param allowedSourceAddressPrefix the allowedSourceAddressPrefix value to set.
* @return the JitNetworkAccessPortRule object itself.
*/
public JitNetworkAccessPortRule withAllowedSourceAddressPrefix(String allowedSourceAddressPrefix) {
this.allowedSourceAddressPrefix = allowedSourceAddressPrefix;
return this;
}
/**
* Get the allowedSourceAddressPrefixes property: Mutually exclusive with the "allowedSourceAddressPrefix"
* parameter.
*
* @return the allowedSourceAddressPrefixes value.
*/
public List allowedSourceAddressPrefixes() {
return this.allowedSourceAddressPrefixes;
}
/**
* Set the allowedSourceAddressPrefixes property: Mutually exclusive with the "allowedSourceAddressPrefix"
* parameter.
*
* @param allowedSourceAddressPrefixes the allowedSourceAddressPrefixes value to set.
* @return the JitNetworkAccessPortRule object itself.
*/
public JitNetworkAccessPortRule withAllowedSourceAddressPrefixes(List allowedSourceAddressPrefixes) {
this.allowedSourceAddressPrefixes = allowedSourceAddressPrefixes;
return this;
}
/**
* Get the maxRequestAccessDuration property: Maximum duration requests can be made for. In ISO 8601 duration
* format. Minimum 5 minutes, maximum 1 day.
*
* @return the maxRequestAccessDuration value.
*/
public String maxRequestAccessDuration() {
return this.maxRequestAccessDuration;
}
/**
* Set the maxRequestAccessDuration property: Maximum duration requests can be made for. In ISO 8601 duration
* format. Minimum 5 minutes, maximum 1 day.
*
* @param maxRequestAccessDuration the maxRequestAccessDuration value to set.
* @return the JitNetworkAccessPortRule object itself.
*/
public JitNetworkAccessPortRule withMaxRequestAccessDuration(String maxRequestAccessDuration) {
this.maxRequestAccessDuration = maxRequestAccessDuration;
return this;
}
/**
* Validates the instance.
*
* @throws IllegalArgumentException thrown if the instance is not valid.
*/
public void validate() {
if (protocol() == null) {
throw LOGGER.atError()
.log(new IllegalArgumentException(
"Missing required property protocol in model JitNetworkAccessPortRule"));
}
if (maxRequestAccessDuration() == null) {
throw LOGGER.atError()
.log(new IllegalArgumentException(
"Missing required property maxRequestAccessDuration in model JitNetworkAccessPortRule"));
}
}
private static final ClientLogger LOGGER = new ClientLogger(JitNetworkAccessPortRule.class);
/**
* {@inheritDoc}
*/
@Override
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
jsonWriter.writeStartObject();
jsonWriter.writeIntField("number", this.number);
jsonWriter.writeStringField("protocol", this.protocol == null ? null : this.protocol.toString());
jsonWriter.writeStringField("maxRequestAccessDuration", this.maxRequestAccessDuration);
jsonWriter.writeStringField("allowedSourceAddressPrefix", this.allowedSourceAddressPrefix);
jsonWriter.writeArrayField("allowedSourceAddressPrefixes", this.allowedSourceAddressPrefixes,
(writer, element) -> writer.writeString(element));
return jsonWriter.writeEndObject();
}
/**
* Reads an instance of JitNetworkAccessPortRule from the JsonReader.
*
* @param jsonReader The JsonReader being read.
* @return An instance of JitNetworkAccessPortRule 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 JitNetworkAccessPortRule.
*/
public static JitNetworkAccessPortRule fromJson(JsonReader jsonReader) throws IOException {
return jsonReader.readObject(reader -> {
JitNetworkAccessPortRule deserializedJitNetworkAccessPortRule = new JitNetworkAccessPortRule();
while (reader.nextToken() != JsonToken.END_OBJECT) {
String fieldName = reader.getFieldName();
reader.nextToken();
if ("number".equals(fieldName)) {
deserializedJitNetworkAccessPortRule.number = reader.getInt();
} else if ("protocol".equals(fieldName)) {
deserializedJitNetworkAccessPortRule.protocol = Protocol.fromString(reader.getString());
} else if ("maxRequestAccessDuration".equals(fieldName)) {
deserializedJitNetworkAccessPortRule.maxRequestAccessDuration = reader.getString();
} else if ("allowedSourceAddressPrefix".equals(fieldName)) {
deserializedJitNetworkAccessPortRule.allowedSourceAddressPrefix = reader.getString();
} else if ("allowedSourceAddressPrefixes".equals(fieldName)) {
List allowedSourceAddressPrefixes = reader.readArray(reader1 -> reader1.getString());
deserializedJitNetworkAccessPortRule.allowedSourceAddressPrefixes = allowedSourceAddressPrefixes;
} else {
reader.skipChildren();
}
}
return deserializedJitNetworkAccessPortRule;
});
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy