-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Endpoint Resolver Implementation
This commit adds `EndpointDecorator`, standard libary + tests that can be used to add endpoints 2.0 to the AWS SDK. It _does not_ actually wire these things up. We'll follow up with a PR that actually integrates everything.
- Loading branch information
Showing
49 changed files
with
2,050 additions
and
185 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
60 changes: 60 additions & 0 deletions
60
aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsEndpointsStdLib.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.rustsdk | ||
|
||
import software.amazon.smithy.model.node.Node | ||
import software.amazon.smithy.model.node.ObjectNode | ||
import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext | ||
import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator | ||
import software.amazon.smithy.rust.codegen.client.smithy.endpoint.CustomRuntimeFunction | ||
import software.amazon.smithy.rust.codegen.client.smithy.endpoint.EndpointCustomization | ||
import software.amazon.smithy.rust.codegen.client.smithy.endpoint.rulesgen.awsStandardLib | ||
import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator | ||
import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext | ||
import kotlin.io.path.readText | ||
|
||
/** | ||
* Standard library functions for AWS-specific endpoint standard library functions. | ||
* | ||
* This decorator uses partitions.json to source a default partition map for the partition resolver (when used). | ||
* | ||
* For test purposes, [awsStandardLib] can be used directly with a manually supplied partitions.json | ||
*/ | ||
class AwsEndpointsStdLib() : RustCodegenDecorator<ClientProtocolGenerator, ClientCodegenContext> { | ||
private var partitionsCache: ObjectNode? = null | ||
override val name: String = "AwsEndpointsStdLib" | ||
override val order: Byte = 0 | ||
|
||
override fun supportsCodegenContext(clazz: Class<out CodegenContext>): Boolean { | ||
return clazz.isAssignableFrom(ClientCodegenContext::class.java) | ||
} | ||
|
||
private fun partitionsDotjson(sdkSettings: SdkSettings): ObjectNode { | ||
if (partitionsCache == null) { | ||
val partitionsJson = when (val path = sdkSettings.partitionsDotJson) { | ||
null -> ( | ||
javaClass.getResource("/default-partitions.json") | ||
?: throw IllegalStateException("Failed to find default-default-partitions.json in the JAR") | ||
).readText() | ||
|
||
else -> path.readText() | ||
} | ||
partitionsCache = Node.parse(partitionsJson).expectObjectNode() | ||
} | ||
return partitionsCache!! | ||
} | ||
|
||
override fun endpointCustomizations(codegenContext: ClientCodegenContext): List<EndpointCustomization> { | ||
return listOf<EndpointCustomization>( | ||
object : EndpointCustomization { | ||
override fun customRuntimeFunctions(codegenContext: ClientCodegenContext): List<CustomRuntimeFunction> { | ||
val sdkSettings = SdkSettings.from(codegenContext.settings) | ||
return awsStandardLib(codegenContext.runtimeConfig, partitionsDotjson(sdkSettings)) | ||
} | ||
}, | ||
) | ||
} | ||
} |
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
105 changes: 105 additions & 0 deletions
105
aws/sdk-codegen/src/main/resources/default-partitions.json
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,105 @@ | ||
{ | ||
"version": "1.1", | ||
"partitions": [ | ||
{ | ||
"id": "aws", | ||
"regionRegex": "^(us|eu|ap|sa|ca|me|af)-\\w+-\\d+$", | ||
"regions": { | ||
"af-south-1": {}, | ||
"ap-east-1": {}, | ||
"ap-northeast-1": {}, | ||
"ap-northeast-2": {}, | ||
"ap-northeast-3": {}, | ||
"ap-south-1": {}, | ||
"ap-southeast-1": {}, | ||
"ap-southeast-2": {}, | ||
"ap-southeast-3": {}, | ||
"ca-central-1": {}, | ||
"eu-central-1": {}, | ||
"eu-north-1": {}, | ||
"eu-south-1": {}, | ||
"eu-west-1": {}, | ||
"eu-west-2": {}, | ||
"eu-west-3": {}, | ||
"me-central-1": {}, | ||
"me-south-1": {}, | ||
"sa-east-1": {}, | ||
"us-east-1": {}, | ||
"us-east-2": {}, | ||
"us-west-1": {}, | ||
"us-west-2": {}, | ||
"aws-global": {} | ||
}, | ||
"outputs": { | ||
"name": "aws", | ||
"dnsSuffix": "amazonaws.com", | ||
"dualStackDnsSuffix": "api.aws", | ||
"supportsFIPS": true, | ||
"supportsDualStack": true | ||
} | ||
}, | ||
{ | ||
"id": "aws-us-gov", | ||
"regionRegex": "^us\\-gov\\-\\w+\\-\\d+$", | ||
"regions": { | ||
"us-gov-west-1": {}, | ||
"us-gov-east-1": {}, | ||
"aws-us-gov-global": {} | ||
}, | ||
"outputs": { | ||
"name": "aws-us-gov", | ||
"dnsSuffix": "amazonaws.com", | ||
"dualStackDnsSuffix": "api.aws", | ||
"supportsFIPS": true, | ||
"supportsDualStack": true | ||
} | ||
}, | ||
{ | ||
"id": "aws-cn", | ||
"regionRegex": "^cn\\-\\w+\\-\\d+$", | ||
"regions": { | ||
"cn-north-1": {}, | ||
"cn-northwest-1": {}, | ||
"aws-cn-global": {} | ||
}, | ||
"outputs": { | ||
"name": "aws-cn", | ||
"dnsSuffix": "amazonaws.com.cn", | ||
"dualStackDnsSuffix": "api.amazonwebservices.com.cn", | ||
"supportsFIPS": true, | ||
"supportsDualStack": true | ||
} | ||
}, | ||
{ | ||
"id": "aws-iso", | ||
"regionRegex": "^us\\-iso\\-\\w+\\-\\d+$", | ||
"outputs": { | ||
"name": "aws-iso", | ||
"dnsSuffix": "c2s.ic.gov", | ||
"supportsFIPS": true, | ||
"supportsDualStack": false, | ||
"dualStackDnsSuffix": "c2s.ic.gov" | ||
}, | ||
"regions": { | ||
"us-iso-east-1": {}, | ||
"us-iso-west-1": {}, | ||
"aws-iso-global": {} | ||
} | ||
}, | ||
{ | ||
"id": "aws-iso-b", | ||
"regionRegex": "^us\\-isob\\-\\w+\\-\\d+$", | ||
"outputs": { | ||
"name": "aws-iso-b", | ||
"dnsSuffix": "sc2s.sgov.gov", | ||
"supportsFIPS": true, | ||
"supportsDualStack": false, | ||
"dualStackDnsSuffix": "sc2s.sgov.gov" | ||
}, | ||
"regions": { | ||
"us-isob-east-1": {}, | ||
"aws-iso-b-global": {} | ||
} | ||
} | ||
] | ||
} |
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.