Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove ByteArrayContent and rename transform package #1062

Merged
merged 5 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/b0f89880-988f-46c1-87dc-f1741587860d.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": "b0f89880-988f-46c1-87dc-f1741587860d",
"type": "misc",
"description": "Track upstream changes that make `ByteArrayContent` and friends internal. Users should only be using `ByteStream.fromBytes()`, `ByteStream.fromString()`, and `HttpBody.fromBytes()`."
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import aws.sdk.kotlin.runtime.config.AwsSdkSetting
import aws.smithy.kotlin.runtime.auth.awscredentials.Credentials
import aws.smithy.kotlin.runtime.auth.awscredentials.CredentialsProviderException
import aws.smithy.kotlin.runtime.http.Headers
import aws.smithy.kotlin.runtime.http.HttpBody
import aws.smithy.kotlin.runtime.http.HttpMethod
import aws.smithy.kotlin.runtime.http.HttpStatusCode
import aws.smithy.kotlin.runtime.http.content.ByteArrayContent
import aws.smithy.kotlin.runtime.http.request.HttpRequest
import aws.smithy.kotlin.runtime.http.request.HttpRequestBuilder
import aws.smithy.kotlin.runtime.http.request.header
Expand Down Expand Up @@ -54,15 +54,15 @@ class EcsCredentialsProviderTest {
"Expiration" : "${expectedExpiration.format(TimestampFormat.ISO_8601)}"
}
""".encodeToByteArray()
return HttpResponse(HttpStatusCode.OK, Headers.Empty, ByteArrayContent(payload))
return HttpResponse(HttpStatusCode.OK, Headers.Empty, HttpBody.fromBytes(payload))
}

private fun errorResponse(
statusCode: HttpStatusCode = HttpStatusCode.BadRequest,
headers: Headers = Headers.Empty,
body: String = "",
): HttpResponse =
HttpResponse(statusCode, headers, ByteArrayContent(body.encodeToByteArray()))
HttpResponse(statusCode, headers, HttpBody.fromBytes(body.encodeToByteArray()))

private fun ecsRequest(url: String, authToken: String? = null): HttpRequest {
val resolvedUrl = Url.parse(url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import aws.smithy.kotlin.runtime.http.HttpBody
import aws.smithy.kotlin.runtime.http.HttpCall
import aws.smithy.kotlin.runtime.http.HttpMethod
import aws.smithy.kotlin.runtime.http.HttpStatusCode
import aws.smithy.kotlin.runtime.http.content.ByteArrayContent
import aws.smithy.kotlin.runtime.http.engine.HttpClientEngineBase
import aws.smithy.kotlin.runtime.http.engine.HttpClientEngineConfig
import aws.smithy.kotlin.runtime.http.request.HttpRequest
Expand Down Expand Up @@ -241,7 +240,7 @@ class ImdsCredentialsProviderTest {
HttpResponse(
HttpStatusCode.NotFound,
Headers.Empty,
ByteArrayContent(
HttpBody.fromBytes(
"""<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import aws.smithy.kotlin.runtime.auth.awscredentials.Credentials
import aws.smithy.kotlin.runtime.http.Headers
import aws.smithy.kotlin.runtime.http.HttpBody
import aws.smithy.kotlin.runtime.http.HttpStatusCode
import aws.smithy.kotlin.runtime.http.content.ByteArrayContent
import aws.smithy.kotlin.runtime.http.response.HttpResponse
import aws.smithy.kotlin.runtime.httptest.TestConnection
import aws.smithy.kotlin.runtime.httptest.buildTestConnection
Expand Down Expand Up @@ -169,7 +168,7 @@ class SsoCredentialsProviderTest {

val engine = buildTestConnection {
expect(
HttpResponse(HttpStatusCode.OK, Headers.Empty, ByteArrayContent(serviceResp.encodeToByteArray())),
HttpResponse(HttpStatusCode.OK, Headers.Empty, HttpBody.fromBytes(serviceResp.encodeToByteArray())),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ package aws.sdk.kotlin.runtime.auth.credentials
import aws.sdk.kotlin.runtime.auth.credentials.internal.sts.model.RegionDisabledException
import aws.smithy.kotlin.runtime.auth.awscredentials.CredentialsProviderException
import aws.smithy.kotlin.runtime.http.Headers
import aws.smithy.kotlin.runtime.http.HttpBody
import aws.smithy.kotlin.runtime.http.HttpStatusCode
import aws.smithy.kotlin.runtime.http.content.ByteArrayContent
import aws.smithy.kotlin.runtime.http.response.HttpResponse
import aws.smithy.kotlin.runtime.httptest.CallAsserter
import aws.smithy.kotlin.runtime.httptest.buildTestConnection
Expand Down Expand Up @@ -105,7 +105,7 @@ class StsAssumeRoleCredentialsProviderTest {
</ErrorResponse>
"""
val testEngine = buildTestConnection {
expect(HttpResponse(HttpStatusCode.BadRequest, Headers.Empty, ByteArrayContent(errorResponseBody.encodeToByteArray())))
expect(HttpResponse(HttpStatusCode.BadRequest, Headers.Empty, HttpBody.fromBytes(errorResponseBody.encodeToByteArray())))
}

val provider = StsAssumeRoleCredentialsProvider(
Expand All @@ -132,7 +132,7 @@ class StsAssumeRoleCredentialsProviderTest {
</ErrorResponse>
"""
val testEngine = buildTestConnection {
expect(HttpResponse(HttpStatusCode.Forbidden, Headers.Empty, ByteArrayContent(errorResponseBody.encodeToByteArray())))
expect(HttpResponse(HttpStatusCode.Forbidden, Headers.Empty, HttpBody.fromBytes(errorResponseBody.encodeToByteArray())))
}

val provider = StsAssumeRoleCredentialsProvider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import aws.smithy.kotlin.runtime.http.Headers
import aws.smithy.kotlin.runtime.http.HttpBody
import aws.smithy.kotlin.runtime.http.HttpMethod
import aws.smithy.kotlin.runtime.http.HttpStatusCode
import aws.smithy.kotlin.runtime.http.content.ByteArrayContent
import aws.smithy.kotlin.runtime.http.request.HttpRequestBuilder
import aws.smithy.kotlin.runtime.http.request.url
import aws.smithy.kotlin.runtime.http.response.HttpResponse
Expand Down Expand Up @@ -76,6 +75,6 @@ object StsTestUtils {
</ResponseMetadata>
</AssumeRoleResponse>
""".trimIndent()
return HttpResponse(HttpStatusCode.OK, Headers.Empty, ByteArrayContent(body.encodeToByteArray()))
return HttpResponse(HttpStatusCode.OK, Headers.Empty, HttpBody.fromBytes(body.encodeToByteArray()))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ package aws.sdk.kotlin.runtime.auth.credentials
import aws.smithy.kotlin.runtime.auth.awscredentials.Credentials
import aws.smithy.kotlin.runtime.auth.awscredentials.CredentialsProviderException
import aws.smithy.kotlin.runtime.http.Headers
import aws.smithy.kotlin.runtime.http.HttpBody
import aws.smithy.kotlin.runtime.http.HttpStatusCode
import aws.smithy.kotlin.runtime.http.content.ByteArrayContent
import aws.smithy.kotlin.runtime.http.response.HttpResponse
import aws.smithy.kotlin.runtime.httptest.CallAsserter
import aws.smithy.kotlin.runtime.httptest.TestConnection
Expand Down Expand Up @@ -67,7 +67,7 @@ class StsWebIdentityCredentialsProviderTest {
</AssumeRoleWithWebIdentityResponse>
""".trimIndent()

return HttpResponse(HttpStatusCode.OK, Headers.Empty, ByteArrayContent(body.encodeToByteArray()))
return HttpResponse(HttpStatusCode.OK, Headers.Empty, HttpBody.fromBytes(body.encodeToByteArray()))
}

@Test
Expand Down Expand Up @@ -160,7 +160,7 @@ class StsWebIdentityCredentialsProviderTest {
"""

val testEngine = buildTestConnection {
expect(HttpResponse(HttpStatusCode.BadRequest, Headers.Empty, ByteArrayContent(errorResponseBody.encodeToByteArray())))
expect(HttpResponse(HttpStatusCode.BadRequest, Headers.Empty, HttpBody.fromBytes(errorResponseBody.encodeToByteArray())))
}

val testPlatform = TestPlatformProvider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
package aws.sdk.kotlin.runtime.config.imds

import aws.smithy.kotlin.runtime.http.Headers
import aws.smithy.kotlin.runtime.http.HttpBody
import aws.smithy.kotlin.runtime.http.HttpMethod
import aws.smithy.kotlin.runtime.http.HttpStatusCode
import aws.smithy.kotlin.runtime.http.content.ByteArrayContent
import aws.smithy.kotlin.runtime.http.request.HttpRequest
import aws.smithy.kotlin.runtime.http.request.url
import aws.smithy.kotlin.runtime.http.response.HttpResponse
Expand All @@ -27,7 +27,7 @@ fun tokenResponse(ttl: Int, token: String): HttpResponse = HttpResponse(
Headers {
append(X_AWS_EC2_METADATA_TOKEN_TTL_SECONDS, ttl.toString())
},
ByteArrayContent(token.encodeToByteArray()),
HttpBody.fromBytes(token.encodeToByteArray()),
)

fun imdsRequest(url: String, token: String): HttpRequest = HttpRequest {
Expand All @@ -39,5 +39,5 @@ fun imdsRequest(url: String, token: String): HttpRequest = HttpRequest {
fun imdsResponse(body: String): HttpResponse = HttpResponse(
HttpStatusCode.OK,
Headers.Empty,
ByteArrayContent(body.encodeToByteArray()),
HttpBody.fromBytes(body.encodeToByteArray()),
)
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class PresignerGenerator : KotlinIntegration {
val serializerSymbol = buildSymbol {
definitionFile = "${op.serializerName()}.kt"
name = op.serializerName()
namespace = "${ctx.settings.pkg.name}.transform"
namespace = ctx.settings.pkg.serde
}

val contextMap: Map<SectionKey<*>, Any> = mapOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class S3Generator : RestXml() {
val errSymbol = ctx.symbolProvider.toSymbol(ctx.model.expectShape(err))
val errDeserializerSymbol = buildSymbol {
name = "${errSymbol.name}Deserializer"
namespace = "${ctx.settings.pkg.name}.transform"
namespace = ctx.settings.pkg.serde
}
writer.write("#S -> #T().deserialize(context, wrappedCall)", getErrorCode(ctx, err), errDeserializerSymbol)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ class RestJson1 : JsonHttpBindingProtocolGenerator() {
val target = ctx.model.expectShape(httpPayload.member.target)
writer.withBlock("if (input.#L == null) {", "}", memberName) {
if (target is StructureShape) {
addImport(RuntimeTypes.Http.ByteArrayContent)
write("builder.body = #T(#S.encodeToByteArray())", RuntimeTypes.Http.ByteArrayContent, "{}")
write("builder.body = #T.fromBytes(#S.encodeToByteArray())", RuntimeTypes.Http.HttpBody, "{}")
}
// Content-Type still needs to be set for non-structured payloads
// https://github.com/awslabs/smithy/blob/main/smithy-aws-protocol-tests/model/restJson1/http-content-type.smithy#L174
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class RestXmlParserGenerator(
return buildSymbol {
val xmlName = xmlNameTrait.value.replaceFirstChar(Char::uppercase)
name = "deserialize${memberSymbol.name}PayloadWithXmlName$xmlName"
namespace = ctx.settings.pkg.subpackage("transform")
namespace = ctx.settings.pkg.serde
definitionFile = "${memberSymbol.name}PayloadDeserializer.kt"
renderBy = { writer ->
addNestedDocumentDeserializers(ctx, targetShape, writer)
Expand Down Expand Up @@ -145,7 +145,7 @@ class RestXmlSerializerGenerator(
return buildSymbol {
val xmlName = xmlNameTrait.value.replaceFirstChar(Char::uppercase)
name = "serialize${memberSymbol.name}PayloadWithXmlName$xmlName"
namespace = ctx.settings.pkg.subpackage("transform")
namespace = ctx.settings.pkg.serde
// TODO - it would be nice to just inline this into the operation file as a private function instead
// since that is the only place it should be accessed
definitionFile = "${memberSymbol.name}PayloadSerializer.kt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ abstract class AwsHttpBindingProtocolGenerator : HttpBindingProtocolGenerator()
val errSymbol = ctx.symbolProvider.toSymbol(ctx.model.expectShape(err))
val errDeserializerSymbol = buildSymbol {
name = "${errSymbol.name}Deserializer"
namespace = "${ctx.settings.pkg.name}.transform"
namespace = ctx.settings.pkg.serde
}
writer.write("#S -> #T().deserialize(context, wrappedCall)", getErrorCode(ctx, err), errDeserializerSymbol)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ abstract class QueryHttpBindingProtocolGenerator : AwsHttpBindingProtocolGenerat
val service = ctx.model.expectShape<ServiceShape>(ctx.settings.service)
val version = service.version
writer.write("""val content = "Action=$action&Version=$version"""")
writer.write("builder.body = #T(content.encodeToByteArray())", RuntimeTypes.Http.ByteArrayContent)
writer.write("builder.body = #T.fromBytes(content.encodeToByteArray())", RuntimeTypes.Http.HttpBody)
} else {
super.renderSerializeHttpBody(ctx, op, writer)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class EventStreamSerializerGenerator(
val streamSymbol = ctx.symbolProvider.toSymbol(streamShape)
val fnName = "encode${op.capitalizedDefaultName()}${streamSymbol.name}EventMessage"
name = fnName
namespace = ctx.settings.pkg.subpackage("transform")
namespace = ctx.settings.pkg.serde
// place it in same file as the operation serializer
definitionFile = "${op.serializerName()}.kt"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ class AwsHttpBindingProtocolGeneratorTest {
val fn = unit.operationErrorHandler(testCtx.generationCtx, op)

// use the symbol to ensure it's generated via GeneratedDependency
testCtx.generationCtx.delegator.useFileWriter("GetFooOperationDeserializer.kt", "com.test.transform") {
testCtx.generationCtx.delegator.useFileWriter("GetFooOperationDeserializer.kt", "com.test.serde") {
it.write("#T(context, response)", fn)
}

testCtx.generationCtx.delegator.finalize()
testCtx.generationCtx.delegator.flushWriters()
val actual = testCtx.manifest.expectFileString("src/main/kotlin/com/test/transform/GetFooOperationDeserializer.kt")
val actual = testCtx.manifest.expectFileString("src/main/kotlin/com/test/serde/GetFooOperationDeserializer.kt")
val expected = """
throw ${serviceSdkName}Exception("Failed to parse response as 'restJson1' error", ex).also {
""".trimIndent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package aws.sdk.kotlin.services.glacier.internal
import aws.smithy.kotlin.runtime.content.ByteStream
import aws.smithy.kotlin.runtime.hashing.HashFunction
import aws.smithy.kotlin.runtime.hashing.Sha256
import aws.smithy.kotlin.runtime.http.content.ByteArrayContent
import aws.smithy.kotlin.runtime.http.HttpBody
import aws.smithy.kotlin.runtime.http.toHttpBody
import aws.smithy.kotlin.runtime.io.SdkBuffer
import aws.smithy.kotlin.runtime.io.SdkByteChannel
Expand Down Expand Up @@ -37,7 +37,7 @@ class TreeHasherTest {
val chunkSize = 3
val hasher = TreeHasherImpl(chunkSize) { RollingSumHashFunction(chunkSize) }

val body = ByteArrayContent(payload)
val body = HttpBody.fromBytes(payload)
val hashes = hasher.calculateHashes(body)

assertContentEquals(fullHash, hashes.fullHash)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package aws.sdk.kotlin.services.route53.internal

import aws.sdk.kotlin.services.route53.model.InvalidChangeBatch
import aws.sdk.kotlin.services.route53.model.Route53Exception
import aws.sdk.kotlin.services.route53.transform.ChangeResourceRecordSetsOperationDeserializer
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package aws.sdk.kotlin.services.s3.internal

import aws.sdk.kotlin.services.s3.model.BucketLocationConstraint
import aws.sdk.kotlin.services.s3.model.S3Exception
import aws.sdk.kotlin.services.s3.transform.GetBucketLocationOperationDeserializer
import aws.sdk.kotlin.services.s3.serde.GetBucketLocationOperationDeserializer
import aws.smithy.kotlin.runtime.http.Headers
import aws.smithy.kotlin.runtime.http.HttpBody
import aws.smithy.kotlin.runtime.http.HttpCall
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

import aws.sdk.kotlin.runtime.auth.credentials.StaticCredentialsProvider
import aws.sdk.kotlin.test.eventstream.restjson1.model.*
import aws.sdk.kotlin.test.eventstream.restjson1.transform.deserializeTestStreamOpOperationBody
import aws.sdk.kotlin.test.eventstream.restjson1.transform.serializeTestStreamOpOperationBody
import aws.sdk.kotlin.test.eventstream.restjson1.serde.deserializeTestStreamOpOperationBody
import aws.sdk.kotlin.test.eventstream.restjson1.serde.serializeTestStreamOpOperationBody
import aws.smithy.kotlin.runtime.InternalApi
import aws.smithy.kotlin.runtime.auth.awscredentials.Credentials
import aws.smithy.kotlin.runtime.auth.awssigning.AwsSigningAttributes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import aws.sdk.kotlin.test.eventstream.awsjson11.model.MessageWithString
import aws.sdk.kotlin.test.eventstream.awsjson11.model.TestStream
import aws.sdk.kotlin.test.eventstream.awsjson11.model.TestStreamOperationWithInitialRequestResponseRequest
import aws.sdk.kotlin.test.eventstream.awsjson11.model.TestStreamOperationWithInitialRequestResponseResponse
import aws.sdk.kotlin.test.eventstream.awsjson11.transform.deserializeTestStreamOperationWithInitialRequestResponseOperationBody
import aws.sdk.kotlin.test.eventstream.awsjson11.transform.serializeTestStreamOperationWithInitialRequestResponseOperationBody
import aws.sdk.kotlin.test.eventstream.awsjson11.serde.deserializeTestStreamOperationWithInitialRequestResponseOperationBody
import aws.sdk.kotlin.test.eventstream.awsjson11.serde.serializeTestStreamOperationWithInitialRequestResponseOperationBody
import aws.smithy.kotlin.runtime.InternalApi
import aws.smithy.kotlin.runtime.auth.awscredentials.Credentials
import aws.smithy.kotlin.runtime.auth.awssigning.AwsSigningAttributes
Expand Down
Loading