software.amazon.awssdk.services.kms.model.ImportKeyMaterialRequest Maven / Gradle / Ivy
Show all versions of kms Show documentation
/*
* 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.kms.model;
import java.nio.ByteBuffer;
import java.time.Instant;
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.Consumer;
import java.util.function.Function;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration;
import software.amazon.awssdk.core.SdkBytes;
import software.amazon.awssdk.core.SdkField;
import software.amazon.awssdk.core.SdkPojo;
import software.amazon.awssdk.core.adapter.StandardMemberCopier;
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.utils.ToString;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
/**
*/
@Generated("software.amazon.awssdk:codegen")
public final class ImportKeyMaterialRequest extends KmsRequest implements
ToCopyableBuilder {
private static final SdkField KEY_ID_FIELD = SdkField. builder(MarshallingType.STRING).memberName("KeyId")
.getter(getter(ImportKeyMaterialRequest::keyId)).setter(setter(Builder::keyId))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("KeyId").build()).build();
private static final SdkField IMPORT_TOKEN_FIELD = SdkField. builder(MarshallingType.SDK_BYTES)
.memberName("ImportToken").getter(getter(ImportKeyMaterialRequest::importToken)).setter(setter(Builder::importToken))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("ImportToken").build()).build();
private static final SdkField ENCRYPTED_KEY_MATERIAL_FIELD = SdkField. builder(MarshallingType.SDK_BYTES)
.memberName("EncryptedKeyMaterial").getter(getter(ImportKeyMaterialRequest::encryptedKeyMaterial))
.setter(setter(Builder::encryptedKeyMaterial))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("EncryptedKeyMaterial").build())
.build();
private static final SdkField VALID_TO_FIELD = SdkField. builder(MarshallingType.INSTANT)
.memberName("ValidTo").getter(getter(ImportKeyMaterialRequest::validTo)).setter(setter(Builder::validTo))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("ValidTo").build()).build();
private static final SdkField EXPIRATION_MODEL_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("ExpirationModel").getter(getter(ImportKeyMaterialRequest::expirationModelAsString))
.setter(setter(Builder::expirationModel))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("ExpirationModel").build()).build();
private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(KEY_ID_FIELD,
IMPORT_TOKEN_FIELD, ENCRYPTED_KEY_MATERIAL_FIELD, VALID_TO_FIELD, EXPIRATION_MODEL_FIELD));
private final String keyId;
private final SdkBytes importToken;
private final SdkBytes encryptedKeyMaterial;
private final Instant validTo;
private final String expirationModel;
private ImportKeyMaterialRequest(BuilderImpl builder) {
super(builder);
this.keyId = builder.keyId;
this.importToken = builder.importToken;
this.encryptedKeyMaterial = builder.encryptedKeyMaterial;
this.validTo = builder.validTo;
this.expirationModel = builder.expirationModel;
}
/**
*
* The identifier of the symmetric CMK that receives the imported key material. The CMK's Origin
must
* be EXTERNAL
. This must be the same CMK specified in the KeyID
parameter of the
* corresponding GetParametersForImport request.
*
*
* Specify the key ID or the Amazon Resource Name (ARN) of the CMK.
*
*
* For example:
*
*
* -
*
* Key ID: 1234abcd-12ab-34cd-56ef-1234567890ab
*
*
* -
*
* Key ARN: arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab
*
*
*
*
* To get the key ID and key ARN for a CMK, use ListKeys or DescribeKey.
*
*
* @return The identifier of the symmetric CMK that receives the imported key material. The CMK's
* Origin
must be EXTERNAL
. This must be the same CMK specified in the
* KeyID
parameter of the corresponding GetParametersForImport request.
*
* Specify the key ID or the Amazon Resource Name (ARN) of the CMK.
*
*
* For example:
*
*
* -
*
* Key ID: 1234abcd-12ab-34cd-56ef-1234567890ab
*
*
* -
*
* Key ARN: arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab
*
*
*
*
* To get the key ID and key ARN for a CMK, use ListKeys or DescribeKey.
*/
public final String keyId() {
return keyId;
}
/**
*
* The import token that you received in the response to a previous GetParametersForImport request. It must
* be from the same response that contained the public key that you used to encrypt the key material.
*
*
* @return The import token that you received in the response to a previous GetParametersForImport request.
* It must be from the same response that contained the public key that you used to encrypt the key
* material.
*/
public final SdkBytes importToken() {
return importToken;
}
/**
*
* The encrypted key material to import. The key material must be encrypted with the public wrapping key that
* GetParametersForImport returned, using the wrapping algorithm that you specified in the same
* GetParametersForImport
request.
*
*
* @return The encrypted key material to import. The key material must be encrypted with the public wrapping key
* that GetParametersForImport returned, using the wrapping algorithm that you specified in the same
* GetParametersForImport
request.
*/
public final SdkBytes encryptedKeyMaterial() {
return encryptedKeyMaterial;
}
/**
*
* The time at which the imported key material expires. When the key material expires, AWS KMS deletes the key
* material and the CMK becomes unusable. You must omit this parameter when the ExpirationModel
* parameter is set to KEY_MATERIAL_DOES_NOT_EXPIRE
. Otherwise it is required.
*
*
* @return The time at which the imported key material expires. When the key material expires, AWS KMS deletes the
* key material and the CMK becomes unusable. You must omit this parameter when the
* ExpirationModel
parameter is set to KEY_MATERIAL_DOES_NOT_EXPIRE
. Otherwise it
* is required.
*/
public final Instant validTo() {
return validTo;
}
/**
*
* Specifies whether the key material expires. The default is KEY_MATERIAL_EXPIRES
, in which case you
* must include the ValidTo
parameter. When this parameter is set to
* KEY_MATERIAL_DOES_NOT_EXPIRE
, you must omit the ValidTo
parameter.
*
*
* If the service returns an enum value that is not available in the current SDK version, {@link #expirationModel}
* will return {@link ExpirationModelType#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is
* available from {@link #expirationModelAsString}.
*
*
* @return Specifies whether the key material expires. The default is KEY_MATERIAL_EXPIRES
, in which
* case you must include the ValidTo
parameter. When this parameter is set to
* KEY_MATERIAL_DOES_NOT_EXPIRE
, you must omit the ValidTo
parameter.
* @see ExpirationModelType
*/
public final ExpirationModelType expirationModel() {
return ExpirationModelType.fromValue(expirationModel);
}
/**
*
* Specifies whether the key material expires. The default is KEY_MATERIAL_EXPIRES
, in which case you
* must include the ValidTo
parameter. When this parameter is set to
* KEY_MATERIAL_DOES_NOT_EXPIRE
, you must omit the ValidTo
parameter.
*
*
* If the service returns an enum value that is not available in the current SDK version, {@link #expirationModel}
* will return {@link ExpirationModelType#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is
* available from {@link #expirationModelAsString}.
*
*
* @return Specifies whether the key material expires. The default is KEY_MATERIAL_EXPIRES
, in which
* case you must include the ValidTo
parameter. When this parameter is set to
* KEY_MATERIAL_DOES_NOT_EXPIRE
, you must omit the ValidTo
parameter.
* @see ExpirationModelType
*/
public final String expirationModelAsString() {
return expirationModel;
}
@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 + super.hashCode();
hashCode = 31 * hashCode + Objects.hashCode(keyId());
hashCode = 31 * hashCode + Objects.hashCode(importToken());
hashCode = 31 * hashCode + Objects.hashCode(encryptedKeyMaterial());
hashCode = 31 * hashCode + Objects.hashCode(validTo());
hashCode = 31 * hashCode + Objects.hashCode(expirationModelAsString());
return hashCode;
}
@Override
public final boolean equals(Object obj) {
return super.equals(obj) && equalsBySdkFields(obj);
}
@Override
public final boolean equalsBySdkFields(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof ImportKeyMaterialRequest)) {
return false;
}
ImportKeyMaterialRequest other = (ImportKeyMaterialRequest) obj;
return Objects.equals(keyId(), other.keyId()) && Objects.equals(importToken(), other.importToken())
&& Objects.equals(encryptedKeyMaterial(), other.encryptedKeyMaterial())
&& Objects.equals(validTo(), other.validTo())
&& Objects.equals(expirationModelAsString(), other.expirationModelAsString());
}
/**
* 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("ImportKeyMaterialRequest").add("KeyId", keyId()).add("ImportToken", importToken())
.add("EncryptedKeyMaterial", encryptedKeyMaterial()).add("ValidTo", validTo())
.add("ExpirationModel", expirationModelAsString()).build();
}
public final Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "KeyId":
return Optional.ofNullable(clazz.cast(keyId()));
case "ImportToken":
return Optional.ofNullable(clazz.cast(importToken()));
case "EncryptedKeyMaterial":
return Optional.ofNullable(clazz.cast(encryptedKeyMaterial()));
case "ValidTo":
return Optional.ofNullable(clazz.cast(validTo()));
case "ExpirationModel":
return Optional.ofNullable(clazz.cast(expirationModelAsString()));
default:
return Optional.empty();
}
}
@Override
public final List> sdkFields() {
return SDK_FIELDS;
}
private static Function