-
Notifications
You must be signed in to change notification settings - Fork 80
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
fix: Route 53 TrimHostedZone customization is incomplete #1445
Changes from 2 commits
38ffb47
9ace770
f9e845b
3108dc5
3381dd0
ad88ccc
5d0e97b
e0fe7b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
import ClientRuntime | ||
|
||
public struct Route53TrimHostedZoneMiddleware<Input, Output>: ClientRuntime.Middleware { | ||
public let id: Swift.String = "Route53TrimHostedZoneMiddleware" | ||
private let prefixes = ["/hostedzone/", "hostedzone/", "/hostedzone", "hostedzone"] | ||
|
||
private let hostedZoneIDKeyPath: WritableKeyPath<Input, String?> | ||
|
||
public init(_ hostedZoneIDKeyPath: WritableKeyPath<Input, String?>) { | ||
self.hostedZoneIDKeyPath = hostedZoneIDKeyPath | ||
} | ||
|
||
public func handle<H>(context: Context, | ||
input: Input, | ||
next: H) async throws -> ClientRuntime.OperationOutput<Output> | ||
where H: Handler, | ||
Self.MInput == H.Input, | ||
Self.MOutput == H.Output, | ||
Self.Context == H.Context { | ||
guard let hostedZoneId = input[keyPath: hostedZoneIDKeyPath] else { | ||
return try await next.handle(context: context, input: input) | ||
} | ||
var copiedInput = input | ||
let stripped = hostedZoneId.stripFirstMatching(prefixes: prefixes) | ||
copiedInput[keyPath: hostedZoneIDKeyPath] = stripped | ||
return try await next.handle(context: context, input: copiedInput) | ||
} | ||
|
||
public typealias MInput = Input | ||
public typealias MOutput = ClientRuntime.OperationOutput<Output> | ||
public typealias Context = ClientRuntime.HttpContext | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ class Route53TrimHostedZone : SwiftIntegration { | |
override fun enabledForService(model: Model, settings: SwiftSettings): Boolean { | ||
return model.expectShape<ServiceShape>(settings.service).isRoute53 | ||
} | ||
|
||
override fun preprocessModel(model: Model, settings: SwiftSettings): Model { | ||
return ModelTransformer.create().mapShapes(model) { | ||
if (isHostId(it)) { | ||
|
@@ -38,8 +39,7 @@ class Route53TrimHostedZone : SwiftIntegration { | |
val inputShape = MiddlewareShapeUtils.inputShape(ctx.model, operationShape) | ||
val hostedZoneMember = inputShape.members().find { it.hasTrait<TrimHostedZone>() } | ||
if (hostedZoneMember != null) { | ||
StripHostedZoneURLPathMiddleware.renderMiddleware(ctx, operationShape) | ||
operationMiddleware.prependMiddleware(operationShape, StripHostedZoneUrlPathMiddlewareRenderable(ctx.model, ctx.symbolProvider)) | ||
operationMiddleware.prependMiddleware(operationShape, StripHostedZoneURLPathMiddlewareRenderable(ctx.model, ctx.symbolProvider)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The middleware is no longer rendered for each operation that needs it since a reusable one is used instead. |
||
} | ||
} | ||
|
||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,11 @@ import software.amazon.smithy.model.Model | |
import software.amazon.smithy.model.shapes.OperationShape | ||
import software.amazon.smithy.swift.codegen.SwiftWriter | ||
import software.amazon.smithy.swift.codegen.integration.ProtocolGenerator | ||
import software.amazon.smithy.swift.codegen.integration.middlewares.handlers.MiddlewareShapeUtils | ||
import software.amazon.smithy.swift.codegen.middleware.MiddlewarePosition | ||
import software.amazon.smithy.swift.codegen.middleware.MiddlewareRenderable | ||
import software.amazon.smithy.swift.codegen.middleware.MiddlewareStep | ||
|
||
class StripHostedZoneUrlPathMiddlewareRenderable( | ||
class StripHostedZoneURLPathMiddlewareRenderable( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Type renamed |
||
val model: Model, | ||
val symbolProvider: SymbolProvider | ||
) : MiddlewareRenderable { | ||
|
@@ -21,7 +20,6 @@ class StripHostedZoneUrlPathMiddlewareRenderable( | |
override val position = MiddlewarePosition.AFTER | ||
|
||
override fun render(ctx: ProtocolGenerator.GenerationContext, writer: SwiftWriter, op: OperationShape, operationStackName: String) { | ||
val inputShapeName = MiddlewareShapeUtils.inputSymbol(symbolProvider, model, op).name | ||
writer.write("$operationStackName.${middlewareStep.stringValue()}.intercept(position: ${position.stringValue()}, middleware: ${inputShapeName}StripHostedZoneMiddleware())") | ||
writer.write("$operationStackName.${middlewareStep.stringValue()}.intercept(position: ${position.stringValue()}, middleware: Route53TrimHostedZoneMiddleware(\\.hostedZoneId))") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reusable middleware, initialized with a key path, is inserted into the operation stack instead of a code-generated middleware. |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the same as the previously code-generated middleware, except: