-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move default endpoint resolver into a runtime plugin (#3072)
## Motivation and Context In preparation for inlining the old endpoint traits, I'm cleaning up the endpoint resolver behavior. ## Description 1. The `Config` field of `service_runtime_plugin` was unused to I deleted it 2. Store the endpoint resolver in `RuntimeComponents` instead of in operation config. This allows a lot of complex logic around `ConfigOverride` to be removed. 3. Move the default endpoint resolver into a runtime plugin. 4. Don't have a fallback implementation for `EndpointResolver`, allow final construction of `RuntimeComponents` to fail 5. `ServiceRuntimePlugin` has been changed to `Defaults` so that it doesn't overwrite settings set by the service config ## Testing Well covered by existing UT / IT ## Checklist <!--- If a checkbox below is not applicable, then please DELETE it rather than leaving it unchecked --> - [x] I have updated `CHANGELOG.next.toml` if I made changes to the smithy-rs codegen or runtime crates - [x] I have updated `CHANGELOG.next.toml` if I made changes to the AWS SDK, generated SDK code, or SDK runtime crates ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._
- Loading branch information
Showing
18 changed files
with
172 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...ware/amazon/smithy/rust/codegen/client/smithy/customizations/IdempotencyTokenDecorator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package software.amazon.smithy.rust.codegen.client.smithy.customizations | ||
|
||
import software.amazon.smithy.model.shapes.OperationShape | ||
import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext | ||
import software.amazon.smithy.rust.codegen.client.smithy.customize.ClientCodegenDecorator | ||
import software.amazon.smithy.rust.codegen.client.smithy.generators.OperationCustomization | ||
import software.amazon.smithy.rust.codegen.client.smithy.generators.ServiceRuntimePluginCustomization | ||
import software.amazon.smithy.rust.codegen.client.smithy.generators.ServiceRuntimePluginSection | ||
import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ConfigCustomization | ||
import software.amazon.smithy.rust.codegen.client.smithy.generators.config.IdempotencyTokenProviderCustomization | ||
import software.amazon.smithy.rust.codegen.client.smithy.generators.config.needsIdempotencyToken | ||
import software.amazon.smithy.rust.codegen.core.rustlang.rust | ||
import software.amazon.smithy.rust.codegen.core.rustlang.writable | ||
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig | ||
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType | ||
import software.amazon.smithy.rust.codegen.core.util.extendIf | ||
|
||
class IdempotencyTokenDecorator : ClientCodegenDecorator { | ||
override val name: String = "IdempotencyToken" | ||
override val order: Byte = 0 | ||
|
||
private fun enabled(ctx: ClientCodegenContext) = ctx.serviceShape.needsIdempotencyToken(ctx.model) | ||
override fun configCustomizations( | ||
codegenContext: ClientCodegenContext, | ||
baseCustomizations: List<ConfigCustomization>, | ||
): List<ConfigCustomization> = baseCustomizations.extendIf(enabled(codegenContext)) { | ||
IdempotencyTokenProviderCustomization(codegenContext) | ||
} | ||
|
||
override fun operationCustomizations( | ||
codegenContext: ClientCodegenContext, | ||
operation: OperationShape, | ||
baseCustomizations: List<OperationCustomization>, | ||
): List<OperationCustomization> { | ||
return baseCustomizations + IdempotencyTokenGenerator(codegenContext, operation) | ||
} | ||
|
||
override fun serviceRuntimePluginCustomizations( | ||
codegenContext: ClientCodegenContext, | ||
baseCustomizations: List<ServiceRuntimePluginCustomization>, | ||
): List<ServiceRuntimePluginCustomization> { | ||
return baseCustomizations.extendIf(enabled(codegenContext)) { | ||
object : ServiceRuntimePluginCustomization() { | ||
override fun section(section: ServiceRuntimePluginSection) = writable { | ||
if (section is ServiceRuntimePluginSection.AdditionalConfig) { | ||
section.putConfigValue(this, defaultTokenProvider((codegenContext.runtimeConfig))) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun defaultTokenProvider(runtimeConfig: RuntimeConfig) = | ||
writable { rust("#T()", RuntimeType.idempotencyToken(runtimeConfig).resolve("default_provider")) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.