From 352ef1c9dacdf623cfcac1b28bbb32426f5b0339 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Mon, 7 Oct 2024 13:37:11 -0400 Subject: [PATCH] Remove InvalidChangeBatch customization --- ...ourceRecordSetsUnmarshallingIntegration.kt | 42 ------- ...tlin.codegen.integration.KotlinIntegration | 1 - ...eRecordSetsUnmarshallingIntegrationTest.kt | 40 ------- .../ChangeResourceRecordSetsUnmarshalling.kt | 49 -------- ...angeResourceRecordSetsUnmarshallingTest.kt | 109 ------------------ services/route53/model/route53-tests.smithy | 81 ------------- 6 files changed, 322 deletions(-) delete mode 100644 codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/route53/ChangeResourceRecordSetsUnmarshallingIntegration.kt delete mode 100644 codegen/aws-sdk-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/customization/route53/ChangeResourceRecordSetsUnmarshallingIntegrationTest.kt delete mode 100644 services/route53/common/src/aws/sdk/kotlin/services/route53/internal/ChangeResourceRecordSetsUnmarshalling.kt delete mode 100644 services/route53/common/test/aws/sdk/kotlin/services/route53/internal/ChangeResourceRecordSetsUnmarshallingTest.kt delete mode 100644 services/route53/model/route53-tests.smithy diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/route53/ChangeResourceRecordSetsUnmarshallingIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/route53/ChangeResourceRecordSetsUnmarshallingIntegration.kt deleted file mode 100644 index b2fccd7a54b..00000000000 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/route53/ChangeResourceRecordSetsUnmarshallingIntegration.kt +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ -package aws.sdk.kotlin.codegen.customization.route53 - -import aws.sdk.kotlin.codegen.sdkId -import software.amazon.smithy.kotlin.codegen.KotlinSettings -import software.amazon.smithy.kotlin.codegen.aws.protocols.core.AwsHttpBindingProtocolGenerator -import software.amazon.smithy.kotlin.codegen.core.getContextValue -import software.amazon.smithy.kotlin.codegen.core.withBlock -import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration -import software.amazon.smithy.kotlin.codegen.integration.SectionWriterBinding -import software.amazon.smithy.kotlin.codegen.model.expectShape -import software.amazon.smithy.model.Model -import software.amazon.smithy.model.shapes.ServiceShape -import software.amazon.smithy.model.shapes.ShapeId - -class ChangeResourceRecordSetsUnmarshallingIntegration : KotlinIntegration { - private val targetErrorShapeId = ShapeId.from("com.amazonaws.route53#InvalidChangeBatch") - - override val sectionWriters: List = listOf( - SectionWriterBinding(AwsHttpBindingProtocolGenerator.Sections.ProtocolErrorDeserialization) { writer, prevValue -> - val op = writer.getContextValue(AwsHttpBindingProtocolGenerator.Sections.RenderThrowOperationError.Operation) - - if (op.errors.any { it == targetErrorShapeId }) { - writer.withBlock("payload?.let {", "}") { - withBlock("aws.sdk.kotlin.services.route53.internal.parseRestXmlInvalidChangeBatchResponse(payload)?.let {", "}") { - write("setAseErrorMetadata(it.exception, wrappedResponse, it.errorDetails)") - write("throw it.exception") - } - } - writer.write("") - } else { - writer.write(prevValue) - } - }, - ) - - override fun enabledForService(model: Model, settings: KotlinSettings) = - model.expectShape(settings.service).sdkId.equals("route 53", ignoreCase = true) -} diff --git a/codegen/aws-sdk-codegen/src/main/resources/META-INF/services/software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration b/codegen/aws-sdk-codegen/src/main/resources/META-INF/services/software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration index fba8df4f45e..3ef264034df 100644 --- a/codegen/aws-sdk-codegen/src/main/resources/META-INF/services/software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration +++ b/codegen/aws-sdk-codegen/src/main/resources/META-INF/services/software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration @@ -33,7 +33,6 @@ aws.sdk.kotlin.codegen.customization.glacier.GlacierBodyChecksum aws.sdk.kotlin.codegen.customization.polly.PollyPresigner aws.sdk.kotlin.codegen.customization.machinelearning.MachineLearningEndpointCustomization aws.sdk.kotlin.codegen.customization.route53.TrimResourcePrefix -aws.sdk.kotlin.codegen.customization.route53.ChangeResourceRecordSetsUnmarshallingIntegration aws.sdk.kotlin.codegen.customization.ec2.EC2MakePrimitivesOptional aws.sdk.kotlin.codegen.customization.RemoveDefaults aws.sdk.kotlin.codegen.customization.s3.UnsupportedSigningAlgorithmIntegration diff --git a/codegen/aws-sdk-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/customization/route53/ChangeResourceRecordSetsUnmarshallingIntegrationTest.kt b/codegen/aws-sdk-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/customization/route53/ChangeResourceRecordSetsUnmarshallingIntegrationTest.kt deleted file mode 100644 index b46961e0695..00000000000 --- a/codegen/aws-sdk-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/customization/route53/ChangeResourceRecordSetsUnmarshallingIntegrationTest.kt +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ -package aws.sdk.kotlin.codegen.customization.route53 - -import org.junit.jupiter.api.Test -import software.amazon.smithy.kotlin.codegen.test.defaultSettings -import software.amazon.smithy.kotlin.codegen.test.prependNamespaceAndService -import software.amazon.smithy.kotlin.codegen.test.toSmithyModel -import software.amazon.smithy.model.Model -import kotlin.test.assertFalse -import kotlin.test.assertTrue - -class ChangeResourceRecordSetsUnmarshallingIntegrationTest { - @Test - fun nonRoute53ModelIntegration() { - val model = sampleModel("not route 53") - val isEnabledForModel = ChangeResourceRecordSetsUnmarshallingIntegration().enabledForService(model, model.defaultSettings()) - assertFalse(isEnabledForModel) - } - - @Test - fun route53ModelIntegration() { - val model = sampleModel("route 53") - val isEnabledForModel = ChangeResourceRecordSetsUnmarshallingIntegration().enabledForService(model, model.defaultSettings()) - assertTrue(isEnabledForModel) - } -} - -private fun sampleModel(serviceName: String): Model = - """ - @http(method: "PUT", uri: "/foo") - operation Foo { } - - @http(method: "POST", uri: "/bar") - operation Bar { } - """ - .prependNamespaceAndService(operations = listOf("Foo", "Bar"), serviceName = serviceName) - .toSmithyModel() diff --git a/services/route53/common/src/aws/sdk/kotlin/services/route53/internal/ChangeResourceRecordSetsUnmarshalling.kt b/services/route53/common/src/aws/sdk/kotlin/services/route53/internal/ChangeResourceRecordSetsUnmarshalling.kt deleted file mode 100644 index e61e2a62021..00000000000 --- a/services/route53/common/src/aws/sdk/kotlin/services/route53/internal/ChangeResourceRecordSetsUnmarshalling.kt +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ -package aws.sdk.kotlin.services.route53.internal - -import aws.sdk.kotlin.services.route53.model.InvalidChangeBatch -import aws.smithy.kotlin.runtime.awsprotocol.ErrorDetails -import aws.smithy.kotlin.runtime.serde.xml.* - -internal fun parseRestXmlInvalidChangeBatchResponse(payload: ByteArray): InvalidChangeBatchErrorResponse? = - deserializeInvalidChangeBatchError(InvalidChangeBatch.Builder(), payload) - -internal fun deserializeInvalidChangeBatchError(builder: InvalidChangeBatch.Builder, payload: ByteArray): InvalidChangeBatchErrorResponse? { - val root = xmlTagReader(payload) - var requestId: String? = null - - loop@while (true) { - val curr = root.nextTag() ?: break@loop - when (curr.tagName) { - "Message", "message" -> builder.message = curr.data() - "Messages", "messages" -> builder.messages = deserializeMessages(curr) - "RequestId" -> requestId = curr.data() - } - curr.drop() - } - - return InvalidChangeBatchErrorResponse(ErrorDetails("InvalidChangeBatch", builder.message, requestId), builder.build()) -} - -private fun deserializeMessages(root: XmlTagReader): List { - val result = mutableListOf() - loop@while (true) { - val curr = root.nextTag() ?: break@loop - when (curr.tagName) { - "Message" -> { - val el = curr.tryData().getOrNull() ?: continue@loop - result.add(el) - } - } - } - - return result -} - -internal data class InvalidChangeBatchErrorResponse( - val errorDetails: ErrorDetails, - val exception: InvalidChangeBatch, -) diff --git a/services/route53/common/test/aws/sdk/kotlin/services/route53/internal/ChangeResourceRecordSetsUnmarshallingTest.kt b/services/route53/common/test/aws/sdk/kotlin/services/route53/internal/ChangeResourceRecordSetsUnmarshallingTest.kt deleted file mode 100644 index 3b4ecff446d..00000000000 --- a/services/route53/common/test/aws/sdk/kotlin/services/route53/internal/ChangeResourceRecordSetsUnmarshallingTest.kt +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ -package aws.sdk.kotlin.services.route53.internal - -import aws.sdk.kotlin.services.route53.model.InvalidChangeBatch -import aws.sdk.kotlin.services.route53.serde.ChangeResourceRecordSetsOperationDeserializer -import aws.smithy.kotlin.runtime.http.Headers -import aws.smithy.kotlin.runtime.http.HttpBody -import aws.smithy.kotlin.runtime.http.HttpCall -import aws.smithy.kotlin.runtime.http.HttpStatusCode -import aws.smithy.kotlin.runtime.http.request.HttpRequestBuilder -import aws.smithy.kotlin.runtime.http.response.HttpResponse -import aws.smithy.kotlin.runtime.operation.ExecutionContext -import kotlinx.coroutines.runBlocking -import kotlin.test.Test -import kotlin.test.assertEquals -import kotlin.test.assertFailsWith - -class ChangeResourceRecordSetsUnmarshallingTest { - @Test - fun invalidChangeBatchMessage() { - val bodyText = """ - - - - InvalidChangeBatch message - - b25f48e8-84fd-11e6-80d9-574e0c4664cb - - """.trimIndent() - - val response = HttpResponse( - HttpStatusCode.BadRequest, - Headers.Empty, - HttpBody.fromBytes(bodyText.encodeToByteArray()), - ) - - val call = HttpCall(HttpRequestBuilder().build(), response) - - val exception = assertFailsWith { - runBlocking { - ChangeResourceRecordSetsOperationDeserializer().deserialize(ExecutionContext(), call, bodyText.encodeToByteArray()) - } - } - assertEquals(listOf("InvalidChangeBatch message"), exception.messages) - } - - @Test - fun invalidChangeBatchMessage2() { - val bodyText = """ - - - - InvalidChangeBatch message 1 - InvalidChangeBatch message 2 - - b25f48e8-84fd-11e6-80d9-574e0c4664cb - - """.trimIndent() - - val response: HttpResponse = HttpResponse( - HttpStatusCode.BadRequest, - Headers.Empty, - HttpBody.fromBytes(bodyText.encodeToByteArray()), - ) - - val call = HttpCall(HttpRequestBuilder().build(), response) - - val exception = assertFailsWith { - runBlocking { - ChangeResourceRecordSetsOperationDeserializer().deserialize(ExecutionContext(), call, bodyText.encodeToByteArray()) - } - } - assertEquals(listOf("InvalidChangeBatch message 1", "InvalidChangeBatch message 2"), exception.messages) - } - - @Test - fun invalidChangeBatchMessage3() { - val bodyText = """ - - - - InvalidChangeBatch message 1 - InvalidChangeBatch message 2 - - InvalidChangeBatch message 3 - b25f48e8-84fd-11e6-80d9-574e0c4664cb - - """.trimIndent() - - val response: HttpResponse = HttpResponse( - HttpStatusCode.BadRequest, - Headers.Empty, - HttpBody.fromBytes(bodyText.encodeToByteArray()), - ) - - val call = HttpCall(HttpRequestBuilder().build(), response) - - val exception = assertFailsWith { - runBlocking { - ChangeResourceRecordSetsOperationDeserializer().deserialize(ExecutionContext(), call, bodyText.encodeToByteArray()) - } - } - assertEquals(listOf("InvalidChangeBatch message 1", "InvalidChangeBatch message 2"), exception.messages) - assertEquals("InvalidChangeBatch message 3", exception.message) - } -} diff --git a/services/route53/model/route53-tests.smithy b/services/route53/model/route53-tests.smithy deleted file mode 100644 index f30e73777c3..00000000000 --- a/services/route53/model/route53-tests.smithy +++ /dev/null @@ -1,81 +0,0 @@ -$version: "1.0" - -namespace com.amazonaws.route53 - -use smithy.test#httpRequestTests - - -apply ListResourceRecordSets @httpRequestTests([ - { - id: "ListResourceRecordSetsNoTrim", - documentation: "Validates that HostedZoneId isn't trimmed when not prefixed.", - method: "GET", - protocol: "aws.protocols#restXml", - uri: "/2013-04-01/hostedzone/IDOFMYHOSTEDZONE/rrset", - bodyMediaType: "application/xml", - params: { - "HostedZoneId": "IDOFMYHOSTEDZONE" - } - }, - { - id: "ListResourceRecordSetsTrim", - documentation: "Validates that HostedZoneId is trimmed.", - method: "GET", - protocol: "aws.protocols#restXml", - uri: "/2013-04-01/hostedzone/IDOFMYHOSTEDZONE/rrset", - bodyMediaType: "application/xml", - params: { - "HostedZoneId": "hostedzone/IDOFMYHOSTEDZONE" - } - }, - { - id: "ListResourceRecordSetsTrimLeadingSlash", - documentation: "Validates that HostedZoneId is trimmed even with a leading slash.", - method: "GET", - protocol: "aws.protocols#restXml", - uri: "/2013-04-01/hostedzone/IDOFMYHOSTEDZONE/rrset", - bodyMediaType: "application/xml", - params: { - "HostedZoneId": "/hostedzone/IDOFMYHOSTEDZONE" - } - }, - { - id: "ListResourceRecordSetsTrimMultislash", - documentation: "Validates that HostedZoneId isn't over-trimmed.", - method: "GET", - protocol: "aws.protocols#restXml", - uri: "/2013-04-01/hostedzone/IDOFMY%2FHOSTEDZONE/rrset", - bodyMediaType: "application/xml", - params: { - "HostedZoneId": "/hostedzone/IDOFMY/HOSTEDZONE" - } - }, -]) - -apply GetChange @httpRequestTests([ - { - id: "GetChangeTrimChangeId", - documentation: "This test validates that change id is correctly trimmed", - method: "GET", - protocol: "aws.protocols#restXml", - uri: "/2013-04-01/change/SOMECHANGEID", - bodyMediaType: "application/xml", - params: { - "Id": "/change/SOMECHANGEID" - } - }, -]) - -apply GetReusableDelegationSet @httpRequestTests([ - { - id: "GetReusableDelegationSetTrimDelegationSetId", - documentation: "This test validates that delegation set id is correctly trimmed", - method: "GET", - protocol: "aws.protocols#restXml", - uri: "/2013-04-01/delegationset/DELEGATIONSETID", - bodyMediaType: "application/xml", - params: { - "Id": "/delegationset/DELEGATIONSETID" - } - }, -]) \ No newline at end of file