commonMain.aws.sdk.kotlin.services.ec2instanceconnect.serde.SendSerialConsoleSSHPublicKeyOperationDeserializer.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ec2instanceconnect-jvm Show documentation
Show all versions of ec2instanceconnect-jvm Show documentation
The AWS SDK for Kotlin client for EC2 Instance Connect
// Code generated by smithy-kotlin-codegen. DO NOT EDIT!
package aws.sdk.kotlin.services.ec2instanceconnect.serde
import aws.sdk.kotlin.services.ec2instanceconnect.model.Ec2InstanceConnectException
import aws.sdk.kotlin.services.ec2instanceconnect.model.SendSerialConsoleSshPublicKeyResponse
import aws.smithy.kotlin.runtime.awsprotocol.json.RestJsonErrorDeserializer
import aws.smithy.kotlin.runtime.awsprotocol.setAseErrorMetadata
import aws.smithy.kotlin.runtime.awsprotocol.withPayload
import aws.smithy.kotlin.runtime.http.HttpCall
import aws.smithy.kotlin.runtime.http.isSuccess
import aws.smithy.kotlin.runtime.http.operation.HttpDeserializer
import aws.smithy.kotlin.runtime.operation.ExecutionContext
import aws.smithy.kotlin.runtime.serde.SdkFieldDescriptor
import aws.smithy.kotlin.runtime.serde.SdkObjectDescriptor
import aws.smithy.kotlin.runtime.serde.SerialKind
import aws.smithy.kotlin.runtime.serde.asSdkSerializable
import aws.smithy.kotlin.runtime.serde.deserializeList
import aws.smithy.kotlin.runtime.serde.deserializeMap
import aws.smithy.kotlin.runtime.serde.deserializeStruct
import aws.smithy.kotlin.runtime.serde.field
import aws.smithy.kotlin.runtime.serde.json.JsonDeserializer
import aws.smithy.kotlin.runtime.serde.json.JsonSerialName
import aws.smithy.kotlin.runtime.serde.serializeList
import aws.smithy.kotlin.runtime.serde.serializeMap
import aws.smithy.kotlin.runtime.serde.serializeStruct
internal class SendSerialConsoleSSHPublicKeyOperationDeserializer: HttpDeserializer.NonStreaming {
override fun deserialize(context: ExecutionContext, call: HttpCall, payload: ByteArray?): SendSerialConsoleSshPublicKeyResponse {
val response = call.response
if (!response.status.isSuccess()) {
throwSendSerialConsoleSshPublicKeyError(context, call, payload)
}
val builder = SendSerialConsoleSshPublicKeyResponse.Builder()
if (payload != null) {
deserializeSendSerialConsoleSSHPublicKeyOperationBody(builder, payload)
}
builder.correctErrors()
return builder.build()
}
}
private fun throwSendSerialConsoleSshPublicKeyError(context: ExecutionContext, call: HttpCall, payload: ByteArray?): kotlin.Nothing {
val wrappedResponse = call.response.withPayload(payload)
val wrappedCall = call.copy(response = wrappedResponse)
val errorDetails = try {
RestJsonErrorDeserializer.deserialize(call.response.headers, payload)
} catch (ex: Exception) {
throw Ec2InstanceConnectException("Failed to parse response as 'awsJson1_1' error", ex).also {
setAseErrorMetadata(it, wrappedCall.response, null)
}
}
val ex = when(errorDetails.code) {
"EC2InstanceStateInvalidException" -> Ec2InstanceStateInvalidExceptionDeserializer().deserialize(context, wrappedCall, payload)
"SerialConsoleSessionUnavailableException" -> SerialConsoleSessionUnavailableExceptionDeserializer().deserialize(context, wrappedCall, payload)
"InvalidArgsException" -> InvalidArgsExceptionDeserializer().deserialize(context, wrappedCall, payload)
"EC2InstanceUnavailableException" -> Ec2InstanceUnavailableExceptionDeserializer().deserialize(context, wrappedCall, payload)
"EC2InstanceNotFoundException" -> Ec2InstanceNotFoundExceptionDeserializer().deserialize(context, wrappedCall, payload)
"ServiceException" -> ServiceExceptionDeserializer().deserialize(context, wrappedCall, payload)
"AuthException" -> AuthExceptionDeserializer().deserialize(context, wrappedCall, payload)
"EC2InstanceTypeInvalidException" -> Ec2InstanceTypeInvalidExceptionDeserializer().deserialize(context, wrappedCall, payload)
"SerialConsoleSessionUnsupportedException" -> SerialConsoleSessionUnsupportedExceptionDeserializer().deserialize(context, wrappedCall, payload)
"SerialConsoleAccessDisabledException" -> SerialConsoleAccessDisabledExceptionDeserializer().deserialize(context, wrappedCall, payload)
"ThrottlingException" -> ThrottlingExceptionDeserializer().deserialize(context, wrappedCall, payload)
"SerialConsoleSessionLimitExceededException" -> SerialConsoleSessionLimitExceededExceptionDeserializer().deserialize(context, wrappedCall, payload)
else -> Ec2InstanceConnectException(errorDetails.message)
}
setAseErrorMetadata(ex, wrappedResponse, errorDetails)
throw ex
}
private fun deserializeSendSerialConsoleSSHPublicKeyOperationBody(builder: SendSerialConsoleSshPublicKeyResponse.Builder, payload: ByteArray) {
val deserializer = JsonDeserializer(payload)
val REQUESTID_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("RequestId"))
val SUCCESS_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Boolean, JsonSerialName("Success"))
val OBJ_DESCRIPTOR = SdkObjectDescriptor.build {
field(REQUESTID_DESCRIPTOR)
field(SUCCESS_DESCRIPTOR)
}
deserializer.deserializeStruct(OBJ_DESCRIPTOR) {
loop@while (true) {
when (findNextFieldIndex()) {
REQUESTID_DESCRIPTOR.index -> builder.requestId = deserializeString()
SUCCESS_DESCRIPTOR.index -> builder.success = deserializeBoolean()
null -> break@loop
else -> skipValue()
}
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy