Skip to content
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
8 changes: 8 additions & 0 deletions .changes/e7d8178c-4211-443d-b4d9-44d7019aefd1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "e7d8178c-4211-443d-b4d9-44d7019aefd1",
"type": "bugfix",
"description": "Favor `endpointUrl` over endpoint discovery when provided",
"issues": [
"https://github.com/awslabs/aws-sdk-kotlin/issues/1413"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import software.amazon.smithy.kotlin.codegen.model.buildSymbol
import software.amazon.smithy.kotlin.codegen.model.expectShape
import software.amazon.smithy.kotlin.codegen.model.expectTrait
import software.amazon.smithy.kotlin.codegen.rendering.endpoints.EndpointResolverAdapterGenerator
import software.amazon.smithy.kotlin.codegen.rendering.endpoints.SdkEndpointBuiltinIntegration
import software.amazon.smithy.model.shapes.OperationShape
import software.amazon.smithy.model.shapes.ServiceShape

Expand Down Expand Up @@ -80,21 +81,27 @@ class EndpointDiscovererGenerator(private val ctx: CodegenContext, private val d
EndpointResolverAdapterGenerator.getSymbol(ctx.settings),
RuntimeTypes.HttpClient.Operation.EndpointResolver,
) {
write("val identity = request.identity")
write(
"""require(identity is #T) { "Endpoint discovery requires AWS credentials" }""",
RuntimeTypes.Auth.Credentials.AwsCredentials.Credentials,
)
write("")
write("val cacheKey = DiscoveryParams(client.config.region, identity.accessKeyId)")
write("request.context[discoveryParamsKey] = cacheKey")
write("val discoveredHost = cache.get(cacheKey) { discoverHost(client) }")
write("")
write("val originalEndpoint = delegate.resolve(request)")
withBlock("#T(", ")", RuntimeTypes.SmithyClient.Endpoints.Endpoint) {
write("originalEndpoint.uri.copy { host = discoveredHost },")
write("originalEndpoint.headers,")
write("originalEndpoint.attributes,")
// Backported from https://github.com/smithy-lang/smithy-kotlin/pull/1221; replace when merging v1.5 to main
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add this as a subtask to our internal "v1.5 minor version bump" tracker?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this mostly as a hint for the inevitable merge conflict. It's not necessarily a TODO or FIXME because resolving this will have to happen as part of the v1.5 release. I don't think adding this to a tracker is any more valuable then the other merge conflicts we anticipate.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: This could be a TODO or FIXME for discoverability

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Answered in #1240 (comment)

withBlock("if (client.config.#L == null) {", "}", SdkEndpointBuiltinIntegration.EndpointUrlProp.propertyName) {
write("val identity = request.identity")
write(
"""require(identity is #T) { "Endpoint discovery requires AWS credentials" }""",
RuntimeTypes.Auth.Credentials.AwsCredentials.Credentials,
)
write("")
write("val cacheKey = DiscoveryParams(client.config.region, identity.accessKeyId)")
write("request.context[discoveryParamsKey] = cacheKey")
write("val discoveredHost = cache.get(cacheKey) { discoverHost(client) }")
write("")
write("val originalEndpoint = delegate.resolve(request)")
withBlock("#T(", ")", RuntimeTypes.SmithyClient.Endpoints.Endpoint) {
write("originalEndpoint.uri.copy { host = discoveredHost },")
write("originalEndpoint.headers,")
write("originalEndpoint.attributes,")
}
// If user manually specifies endpointUrl, skip endpoint discovery
closeAndOpenBlock("} else {")
write("delegate.resolve(request)")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,23 @@ class EndpointDiscovererGeneratorTest {
actual.shouldContainOnlyOnceWithDiff(
"""
internal fun asEndpointResolver(client: TestClient, delegate: EndpointResolverAdapter) = EndpointResolver { request ->
val identity = request.identity
require(identity is Credentials) { "Endpoint discovery requires AWS credentials" }

val cacheKey = DiscoveryParams(client.config.region, identity.accessKeyId)
request.context[discoveryParamsKey] = cacheKey
val discoveredHost = cache.get(cacheKey) { discoverHost(client) }

val originalEndpoint = delegate.resolve(request)
Endpoint(
originalEndpoint.uri.copy { host = discoveredHost },
originalEndpoint.headers,
originalEndpoint.attributes,
)
if (client.config.endpointUrl == null) {
val identity = request.identity
require(identity is Credentials) { "Endpoint discovery requires AWS credentials" }

val cacheKey = DiscoveryParams(client.config.region, identity.accessKeyId)
request.context[discoveryParamsKey] = cacheKey
val discoveredHost = cache.get(cacheKey) { discoverHost(client) }

val originalEndpoint = delegate.resolve(request)
Endpoint(
originalEndpoint.uri.copy { host = discoveredHost },
originalEndpoint.headers,
originalEndpoint.attributes,
)
} else {
delegate.resolve(request)
}
}
""".formatForTest(),
)
Expand Down
Loading