Skip to content

Commit 2ca4e3f

Browse files
authored
fix: favor endpoint entry when one exists (#157)
Fixes FIPS endpoints for global services like IAM where the region is specified as `iam-fips`.
1 parent d92b86c commit 2ca4e3f

File tree

2 files changed

+29
-5
lines changed
  • client-runtime/aws-client-rt/common

2 files changed

+29
-5
lines changed

client-runtime/aws-client-rt/common/src/aws/sdk/kotlin/runtime/endpoint/internal/Partition.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ internal fun Partition.resolveEndpoint(region: String): Endpoint? {
108108
}
109109

110110
private fun Partition.endpointDefinitionForRegion(region: String): EndpointDefinition {
111-
val match = if (!isRegionalized) {
112-
endpoints[partitionEndpoint]
113-
} else {
114-
endpoints[region]
111+
val match = when {
112+
endpoints.containsKey(region) -> endpoints[region]
113+
!isRegionalized -> endpoints[partitionEndpoint]
114+
else -> null
115115
}
116116

117117
// return a matching definition or create an empty one that will be used for

client-runtime/aws-client-rt/common/test/aws/sdk/kotlin/runtime/endpoint/internal/EndpointsTest.kt

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ val testPartitions = listOf(
4848
"partition" to EndpointDefinition(
4949
hostname = "some-global-thing.amazonaws.cn",
5050
credentialScope = CredentialScope(region = "cn-east-1")
51+
),
52+
"fips-partition" to EndpointDefinition(
53+
hostname = "some-global-thing-fips.amazonaws.cn",
54+
credentialScope = CredentialScope(region = "cn-east-1")
5155
)
5256
)
5357
),
@@ -109,7 +113,27 @@ class EndpointsTest {
109113
signingRegion = "eu-west-1",
110114
signingName = "foo"
111115
)
112-
)
116+
),
117+
ResolveTest(
118+
description = "specified partition endpoint",
119+
region = "partition",
120+
Endpoint(
121+
hostname = "some-global-thing.amazonaws.cn",
122+
protocol = "https",
123+
signingRegion = "cn-east-1",
124+
signingName = "foo"
125+
)
126+
),
127+
ResolveTest(
128+
description = "fips partition endpoint",
129+
region = "fips-partition",
130+
Endpoint(
131+
hostname = "some-global-thing-fips.amazonaws.cn",
132+
protocol = "https",
133+
signingRegion = "cn-east-1",
134+
signingName = "foo"
135+
)
136+
),
113137
)
114138

115139
@Test

0 commit comments

Comments
 (0)