Skip to content

Commit

Permalink
feat!: Provide HTTP request components by closure instead of protocol (
Browse files Browse the repository at this point in the history
  • Loading branch information
jbelkins authored Jan 26, 2024
1 parent ce9f5a0 commit f9be5af
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Sigv4SigningTests: XCTestCase {
.withPort(443)
.withProtocol(.http)
.withHeader(name: "host", value: "example.amazonaws.com")
.withQueryItem(URLQueryItem(name: "%E1%88%B4", value: "bar"))
.withQueryItem(SDKURLQueryItem(name: "%E1%88%B4", value: "bar"))

guard let url = await AWSSigV4Signer.sigV4SignedURL(requestBuilder: requestBuilder,
credentialsProvider: MyCustomCredentialsProvider(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import software.amazon.smithy.model.shapes.ListShape
import software.amazon.smithy.model.shapes.Shape
import software.amazon.smithy.model.shapes.ShapeId
import software.amazon.smithy.model.shapes.TimestampShape
import software.amazon.smithy.swift.codegen.ClientRuntimeTypes.Core.URLQueryItem
import software.amazon.smithy.swift.codegen.ClientRuntimeTypes.Core.SDKURLQueryItem
import software.amazon.smithy.swift.codegen.Middleware
import software.amazon.smithy.swift.codegen.SwiftTypes
import software.amazon.smithy.swift.codegen.SwiftWriter
Expand Down Expand Up @@ -57,7 +57,7 @@ class InputTypeGETQueryItemMiddleware(
}

private fun writeRenderItem(queryKey: String, queryValue: String) {
writer.write("let queryItem = \$N(name: \"${queryKey}\".urlPercentEncoding(), value: \$N($queryValue).urlPercentEncoding())", URLQueryItem, SwiftTypes.String)
writer.write("let queryItem = \$N(name: \"${queryKey}\".urlPercentEncoding(), value: \$N($queryValue).urlPercentEncoding())", SDKURLQueryItem, SwiftTypes.String)
writer.write("input.builder.withQueryItem(queryItem)")
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package software.amazon.smithy.aws.swift.codegen.customization

import software.amazon.smithy.codegen.core.Symbol
import software.amazon.smithy.swift.codegen.ClientRuntimeTypes
import software.amazon.smithy.swift.codegen.Middleware
import software.amazon.smithy.swift.codegen.SwiftWriter
import software.amazon.smithy.swift.codegen.integration.steps.OperationSerializeStep
Expand All @@ -25,7 +26,7 @@ class PutObjectPresignedURLMiddleware(
writer.apply {
write("let metadata = input.operationInput.metadata ?? [:]")
openBlock("for (metadataKey, metadataValue) in metadata {", "}") {
openBlock("let queryItem = URLQueryItem(", ")") {
openBlock("let queryItem = \$N(", ")", ClientRuntimeTypes.Core.SDKURLQueryItem) {
write("name: \"x-amz-meta-\\(metadataKey.urlPercentEncoding())\",")
write("value: metadataValue.urlPercentEncoding()")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ extension EventStreamTestClientTypes.TestStream: ClientRuntime.MessageUnmarshall
.build()
try context.setupBidirectionalStreaming()
var operation = ClientRuntime.OperationStack<TestStreamOpInput, TestStreamOpOutput>(id: "testStreamOp")
operation.initializeStep.intercept(position: .after, middleware: ClientRuntime.URLPathMiddleware<TestStreamOpInput, TestStreamOpOutput>())
operation.initializeStep.intercept(position: .after, middleware: ClientRuntime.URLPathMiddleware<TestStreamOpInput, TestStreamOpOutput>(TestStreamOpInput.urlPathProvider(_:)))
operation.initializeStep.intercept(position: .after, middleware: ClientRuntime.URLHostMiddleware<TestStreamOpInput, TestStreamOpOutput>())
let endpointParams = EndpointParams()
operation.buildStep.intercept(position: .before, middleware: EndpointResolverMiddleware<TestStreamOpOutput>(endpointResolver: config.serviceSpecific.endpointResolver, endpointParams: endpointParams))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ extension GetFooInput {
.withSigningRegion(value: config.signingRegion)
.build()
var operation = ClientRuntime.OperationStack<GetFooInput, GetFooOutput>(id: "getFoo")
operation.initializeStep.intercept(position: .after, middleware: ClientRuntime.URLPathMiddleware<GetFooInput, GetFooOutput>())
operation.initializeStep.intercept(position: .after, middleware: ClientRuntime.URLPathMiddleware<GetFooInput, GetFooOutput>(GetFooInput.urlPathProvider(_:)))
operation.initializeStep.intercept(position: .after, middleware: ClientRuntime.URLHostMiddleware<GetFooInput, GetFooOutput>())
let endpointParams = EndpointParams()
operation.buildStep.intercept(position: .before, middleware: EndpointResolverMiddleware<GetFooOutput>(endpointResolver: config.serviceSpecific.endpointResolver, endpointParams: endpointParams))
Expand Down Expand Up @@ -92,7 +92,7 @@ extension PostFooInput {
.withSigningRegion(value: config.signingRegion)
.build()
var operation = ClientRuntime.OperationStack<PostFooInput, PostFooOutput>(id: "postFoo")
operation.initializeStep.intercept(position: .after, middleware: ClientRuntime.URLPathMiddleware<PostFooInput, PostFooOutput>())
operation.initializeStep.intercept(position: .after, middleware: ClientRuntime.URLPathMiddleware<PostFooInput, PostFooOutput>(PostFooInput.urlPathProvider(_:)))
operation.initializeStep.intercept(position: .after, middleware: ClientRuntime.URLHostMiddleware<PostFooInput, PostFooOutput>())
let endpointParams = EndpointParams()
operation.buildStep.intercept(position: .before, middleware: EndpointResolverMiddleware<PostFooOutput>(endpointResolver: config.serviceSpecific.endpointResolver, endpointParams: endpointParams))
Expand Down Expand Up @@ -147,7 +147,7 @@ extension PutFooInput {
.withSigningRegion(value: config.signingRegion)
.build()
var operation = ClientRuntime.OperationStack<PutFooInput, PutFooOutput>(id: "putFoo")
operation.initializeStep.intercept(position: .after, middleware: ClientRuntime.URLPathMiddleware<PutFooInput, PutFooOutput>())
operation.initializeStep.intercept(position: .after, middleware: ClientRuntime.URLPathMiddleware<PutFooInput, PutFooOutput>(PutFooInput.urlPathProvider(_:)))
operation.initializeStep.intercept(position: .after, middleware: ClientRuntime.URLHostMiddleware<PutFooInput, PutFooOutput>())
let endpointParams = EndpointParams()
operation.buildStep.intercept(position: .before, middleware: EndpointResolverMiddleware<PutFooOutput>(endpointResolver: config.serviceSpecific.endpointResolver, endpointParams: endpointParams))
Expand Down Expand Up @@ -202,7 +202,7 @@ extension PutObjectInput {
.withSigningRegion(value: config.signingRegion)
.build()
var operation = ClientRuntime.OperationStack<PutObjectInput, PutObjectOutput>(id: "putObject")
operation.initializeStep.intercept(position: .after, middleware: ClientRuntime.URLPathMiddleware<PutObjectInput, PutObjectOutput>())
operation.initializeStep.intercept(position: .after, middleware: ClientRuntime.URLPathMiddleware<PutObjectInput, PutObjectOutput>(PutObjectInput.urlPathProvider(_:)))
operation.initializeStep.intercept(position: .after, middleware: ClientRuntime.URLHostMiddleware<PutObjectInput, PutObjectOutput>())
let endpointParams = EndpointParams()
operation.buildStep.intercept(position: .before, middleware: EndpointResolverMiddleware<PutObjectOutput>(endpointResolver: config.serviceSpecific.endpointResolver, endpointParams: endpointParams))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class AWSQueryOperationStackTest {
.withRegion(value: config.region)
.build()
var operation = ClientRuntime.OperationStack<NoInputAndOutputInput, NoInputAndOutputOutput>(id: "noInputAndOutput")
operation.initializeStep.intercept(position: .after, middleware: ClientRuntime.URLPathMiddleware<NoInputAndOutputInput, NoInputAndOutputOutput>())
operation.initializeStep.intercept(position: .after, middleware: ClientRuntime.URLPathMiddleware<NoInputAndOutputInput, NoInputAndOutputOutput>(NoInputAndOutputInput.urlPathProvider(_:)))
operation.initializeStep.intercept(position: .after, middleware: ClientRuntime.URLHostMiddleware<NoInputAndOutputInput, NoInputAndOutputOutput>())
let endpointParams = EndpointParams()
operation.buildStep.intercept(position: .before, middleware: EndpointResolverMiddleware<NoInputAndOutputOutput>(endpointResolver: config.serviceSpecific.endpointResolver, endpointParams: endpointParams))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public struct PutObjectPresignedURLMiddleware: ClientRuntime.Middleware {
{
let metadata = input.operationInput.metadata ?? [:]
for (metadataKey, metadataValue) in metadata {
let queryItem = URLQueryItem(
let queryItem = ClientRuntime.SDKURLQueryItem(
name: "x-amz-meta-\(metadataKey.urlPercentEncoding())",
value: metadataValue.urlPercentEncoding()
)
Expand Down

0 comments on commit f9be5af

Please sign in to comment.