software.amazon.awssdk.services.s3.model.Encryption 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.s3.model;
import java.io.Serializable;
import java.util.Arrays;
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.Function;
import software.amazon.awssdk.annotations.Generated;
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.LocationTrait;
import software.amazon.awssdk.core.traits.RequiredTrait;
import software.amazon.awssdk.utils.ToString;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
/**
*
* Contains the type of server-side encryption used.
*
*/
@Generated("software.amazon.awssdk:codegen")
public final class Encryption implements SdkPojo, Serializable, ToCopyableBuilder {
private static final SdkField ENCRYPTION_TYPE_FIELD = SdkField
. builder(MarshallingType.STRING)
.memberName("EncryptionType")
.getter(getter(Encryption::encryptionTypeAsString))
.setter(setter(Builder::encryptionType))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("EncryptionType")
.unmarshallLocationName("EncryptionType").build(), RequiredTrait.create()).build();
private static final SdkField KMS_KEY_ID_FIELD = SdkField
. builder(MarshallingType.STRING)
.memberName("KMSKeyId")
.getter(getter(Encryption::kmsKeyId))
.setter(setter(Builder::kmsKeyId))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("KMSKeyId")
.unmarshallLocationName("KMSKeyId").build()).build();
private static final SdkField KMS_CONTEXT_FIELD = SdkField
. builder(MarshallingType.STRING)
.memberName("KMSContext")
.getter(getter(Encryption::kmsContext))
.setter(setter(Builder::kmsContext))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("KMSContext")
.unmarshallLocationName("KMSContext").build()).build();
private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(ENCRYPTION_TYPE_FIELD,
KMS_KEY_ID_FIELD, KMS_CONTEXT_FIELD));
private static final long serialVersionUID = 1L;
private final String encryptionType;
private final String kmsKeyId;
private final String kmsContext;
private Encryption(BuilderImpl builder) {
this.encryptionType = builder.encryptionType;
this.kmsKeyId = builder.kmsKeyId;
this.kmsContext = builder.kmsContext;
}
/**
*
* The server-side encryption algorithm used when storing job results in Amazon S3 (for example, AES256,
* aws:kms
).
*
*
* If the service returns an enum value that is not available in the current SDK version, {@link #encryptionType}
* will return {@link ServerSideEncryption#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is
* available from {@link #encryptionTypeAsString}.
*
*
* @return The server-side encryption algorithm used when storing job results in Amazon S3 (for example, AES256,
* aws:kms
).
* @see ServerSideEncryption
*/
public final ServerSideEncryption encryptionType() {
return ServerSideEncryption.fromValue(encryptionType);
}
/**
*
* The server-side encryption algorithm used when storing job results in Amazon S3 (for example, AES256,
* aws:kms
).
*
*
* If the service returns an enum value that is not available in the current SDK version, {@link #encryptionType}
* will return {@link ServerSideEncryption#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is
* available from {@link #encryptionTypeAsString}.
*
*
* @return The server-side encryption algorithm used when storing job results in Amazon S3 (for example, AES256,
* aws:kms
).
* @see ServerSideEncryption
*/
public final String encryptionTypeAsString() {
return encryptionType;
}
/**
*
* If the encryption type is aws:kms
, this optional value specifies the ID of the symmetric encryption
* customer managed key to use for encryption of job results. Amazon S3 only supports symmetric encryption KMS keys.
* For more information, see Asymmetric keys in KMS
* in the Amazon Web Services Key Management Service Developer Guide.
*
*
* @return If the encryption type is aws:kms
, this optional value specifies the ID of the symmetric
* encryption customer managed key to use for encryption of job results. Amazon S3 only supports symmetric
* encryption KMS keys. For more information, see Asymmetric keys in
* KMS in the Amazon Web Services Key Management Service Developer Guide.
*/
public final String kmsKeyId() {
return kmsKeyId;
}
/**
*
* If the encryption type is aws:kms
, this optional value can be used to specify the encryption context
* for the restore results.
*
*
* @return If the encryption type is aws:kms
, this optional value can be used to specify the encryption
* context for the restore results.
*/
public final String kmsContext() {
return kmsContext;
}
@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(encryptionTypeAsString());
hashCode = 31 * hashCode + Objects.hashCode(kmsKeyId());
hashCode = 31 * hashCode + Objects.hashCode(kmsContext());
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 Encryption)) {
return false;
}
Encryption other = (Encryption) obj;
return Objects.equals(encryptionTypeAsString(), other.encryptionTypeAsString())
&& Objects.equals(kmsKeyId(), other.kmsKeyId()) && Objects.equals(kmsContext(), other.kmsContext());
}
/**
* 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("Encryption").add("EncryptionType", encryptionTypeAsString())
.add("KMSKeyId", kmsKeyId() == null ? null : "*** Sensitive Data Redacted ***").add("KMSContext", kmsContext())
.build();
}
public final Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "EncryptionType":
return Optional.ofNullable(clazz.cast(encryptionTypeAsString()));
case "KMSKeyId":
return Optional.ofNullable(clazz.cast(kmsKeyId()));
case "KMSContext":
return Optional.ofNullable(clazz.cast(kmsContext()));
default:
return Optional.empty();
}
}
@Override
public final List> sdkFields() {
return SDK_FIELDS;
}
private static Function