software.amazon.awssdk.services.iam.model.VirtualMFADevice Maven / Gradle / Ivy
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
package software.amazon.awssdk.services.iam.model;
import java.io.Serializable;
import java.nio.ByteBuffer;
import java.time.Instant;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.core.SdkBytes;
import software.amazon.awssdk.core.SdkField;
import software.amazon.awssdk.core.SdkPojo;
import software.amazon.awssdk.core.protocol.MarshallLocation;
import software.amazon.awssdk.core.protocol.MarshallingType;
import software.amazon.awssdk.core.traits.ListTrait;
import software.amazon.awssdk.core.traits.LocationTrait;
import software.amazon.awssdk.core.util.DefaultSdkAutoConstructList;
import software.amazon.awssdk.core.util.SdkAutoConstructList;
import software.amazon.awssdk.utils.ToString;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
/**
*
* Contains information about a virtual MFA device.
*
*/
@Generated("software.amazon.awssdk:codegen")
public final class VirtualMFADevice implements SdkPojo, Serializable,
ToCopyableBuilder {
private static final SdkField SERIAL_NUMBER_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("SerialNumber").getter(getter(VirtualMFADevice::serialNumber)).setter(setter(Builder::serialNumber))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("SerialNumber").build()).build();
private static final SdkField BASE32_STRING_SEED_FIELD = SdkField. builder(MarshallingType.SDK_BYTES)
.memberName("Base32StringSeed").getter(getter(VirtualMFADevice::base32StringSeed))
.setter(setter(Builder::base32StringSeed))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Base32StringSeed").build()).build();
private static final SdkField QR_CODE_PNG_FIELD = SdkField. builder(MarshallingType.SDK_BYTES)
.memberName("QRCodePNG").getter(getter(VirtualMFADevice::qrCodePNG)).setter(setter(Builder::qrCodePNG))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("QRCodePNG").build()).build();
private static final SdkField USER_FIELD = SdkField. builder(MarshallingType.SDK_POJO).memberName("User")
.getter(getter(VirtualMFADevice::user)).setter(setter(Builder::user)).constructor(User::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("User").build()).build();
private static final SdkField ENABLE_DATE_FIELD = SdkField. builder(MarshallingType.INSTANT)
.memberName("EnableDate").getter(getter(VirtualMFADevice::enableDate)).setter(setter(Builder::enableDate))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("EnableDate").build()).build();
private static final SdkField> TAGS_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("Tags")
.getter(getter(VirtualMFADevice::tags))
.setter(setter(Builder::tags))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Tags").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.SDK_POJO)
.constructor(Tag::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").build()).build()).build()).build();
private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(SERIAL_NUMBER_FIELD,
BASE32_STRING_SEED_FIELD, QR_CODE_PNG_FIELD, USER_FIELD, ENABLE_DATE_FIELD, TAGS_FIELD));
private static final long serialVersionUID = 1L;
private final String serialNumber;
private final SdkBytes base32StringSeed;
private final SdkBytes qrCodePNG;
private final User user;
private final Instant enableDate;
private final List tags;
private VirtualMFADevice(BuilderImpl builder) {
this.serialNumber = builder.serialNumber;
this.base32StringSeed = builder.base32StringSeed;
this.qrCodePNG = builder.qrCodePNG;
this.user = builder.user;
this.enableDate = builder.enableDate;
this.tags = builder.tags;
}
/**
*
* The serial number associated with VirtualMFADevice
.
*
*
* @return The serial number associated with VirtualMFADevice
.
*/
public final String serialNumber() {
return serialNumber;
}
/**
*
* The base32 seed defined as specified in RFC3548. The
* Base32StringSeed
is base32-encoded.
*
*
* @return The base32 seed defined as specified in RFC3548.
* The Base32StringSeed
is base32-encoded.
*/
public final SdkBytes base32StringSeed() {
return base32StringSeed;
}
/**
*
* A QR code PNG image that encodes
* otpauth://totp/$virtualMFADeviceName@$AccountName?secret=$Base32String
where
* $virtualMFADeviceName
is one of the create call arguments. AccountName
is the user name
* if set (otherwise, the account ID otherwise), and Base32String
is the seed in base32 format. The
* Base32String
value is base64-encoded.
*
*
* @return A QR code PNG image that encodes
* otpauth://totp/$virtualMFADeviceName@$AccountName?secret=$Base32String
where
* $virtualMFADeviceName
is one of the create call arguments. AccountName
is the
* user name if set (otherwise, the account ID otherwise), and Base32String
is the seed in
* base32 format. The Base32String
value is base64-encoded.
*/
public final SdkBytes qrCodePNG() {
return qrCodePNG;
}
/**
*
* The IAM user associated with this virtual MFA device.
*
*
* @return The IAM user associated with this virtual MFA device.
*/
public final User user() {
return user;
}
/**
*
* The date and time on which the virtual MFA device was enabled.
*
*
* @return The date and time on which the virtual MFA device was enabled.
*/
public final Instant enableDate() {
return enableDate;
}
/**
* For responses, this returns true if the service returned a value for the Tags property. This DOES NOT check that
* the value is non-empty (for which, you should check the {@code isEmpty()} method on the property). This is useful
* because the SDK will never return a null collection or map, but you may need to differentiate between the service
* returning nothing (or null) and the service returning an empty collection or map. For requests, this returns true
* if a value for the property was specified in the request builder, and false if a value was not specified.
*/
public final boolean hasTags() {
return tags != null && !(tags instanceof SdkAutoConstructList);
}
/**
*
* A list of tags that are attached to the virtual MFA device. For more information about tagging, see Tagging IAM resources in the IAM User
* Guide.
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* This method will never return null. If you would like to know whether the service returned this field (so that
* you can differentiate between null and empty), you can use the {@link #hasTags} method.
*
*
* @return A list of tags that are attached to the virtual MFA device. For more information about tagging, see Tagging IAM resources in the
* IAM User Guide.
*/
public final List tags() {
return tags;
}
@Override
public Builder toBuilder() {
return new BuilderImpl(this);
}
public static Builder builder() {
return new BuilderImpl();
}
public static Class extends Builder> serializableBuilderClass() {
return BuilderImpl.class;
}
@Override
public final int hashCode() {
int hashCode = 1;
hashCode = 31 * hashCode + Objects.hashCode(serialNumber());
hashCode = 31 * hashCode + Objects.hashCode(base32StringSeed());
hashCode = 31 * hashCode + Objects.hashCode(qrCodePNG());
hashCode = 31 * hashCode + Objects.hashCode(user());
hashCode = 31 * hashCode + Objects.hashCode(enableDate());
hashCode = 31 * hashCode + Objects.hashCode(hasTags() ? tags() : null);
return hashCode;
}
@Override
public final boolean equals(Object obj) {
return equalsBySdkFields(obj);
}
@Override
public final boolean equalsBySdkFields(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof VirtualMFADevice)) {
return false;
}
VirtualMFADevice other = (VirtualMFADevice) obj;
return Objects.equals(serialNumber(), other.serialNumber())
&& Objects.equals(base32StringSeed(), other.base32StringSeed()) && Objects.equals(qrCodePNG(), other.qrCodePNG())
&& Objects.equals(user(), other.user()) && Objects.equals(enableDate(), other.enableDate())
&& hasTags() == other.hasTags() && Objects.equals(tags(), other.tags());
}
/**
* Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be
* redacted from this string using a placeholder value.
*/
@Override
public final String toString() {
return ToString.builder("VirtualMFADevice").add("SerialNumber", serialNumber())
.add("Base32StringSeed", base32StringSeed() == null ? null : "*** Sensitive Data Redacted ***")
.add("QRCodePNG", qrCodePNG() == null ? null : "*** Sensitive Data Redacted ***").add("User", user())
.add("EnableDate", enableDate()).add("Tags", hasTags() ? tags() : null).build();
}
public final Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "SerialNumber":
return Optional.ofNullable(clazz.cast(serialNumber()));
case "Base32StringSeed":
return Optional.ofNullable(clazz.cast(base32StringSeed()));
case "QRCodePNG":
return Optional.ofNullable(clazz.cast(qrCodePNG()));
case "User":
return Optional.ofNullable(clazz.cast(user()));
case "EnableDate":
return Optional.ofNullable(clazz.cast(enableDate()));
case "Tags":
return Optional.ofNullable(clazz.cast(tags()));
default:
return Optional.empty();
}
}
@Override
public final List> sdkFields() {
return SDK_FIELDS;
}
private static Function