Use endpoint config from aws-sdk-rust (#1543)

This commit is contained in:
John DiSanti 2022-07-12 09:43:00 -07:00 committed by GitHub
parent bbdde4bbc4
commit c220b03a18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 1535 additions and 79 deletions

View File

@ -36,21 +36,27 @@ import software.amazon.smithy.rust.codegen.smithy.generators.config.ServiceConfi
import software.amazon.smithy.rust.codegen.util.dq
import software.amazon.smithy.rust.codegen.util.expectTrait
import software.amazon.smithy.rust.codegen.util.orNull
import kotlin.io.path.readText
class AwsEndpointDecorator : RustCodegenDecorator<ClientCodegenContext> {
override val name: String = "AwsEndpoint"
override val order: Byte = 0
private val endpoints by lazy {
val endpointsJson = javaClass.getResource("endpoints.json")!!.readText()
Node.parse(endpointsJson).expectObjectNode()
private var endpointsCache: ObjectNode? = null
private fun endpoints(sdkSettings: SdkSettings): ObjectNode {
if (endpointsCache == null) {
val endpointsJson = sdkSettings.endpointsConfigPath.readText()
endpointsCache = Node.parse(endpointsJson).expectObjectNode()
}
return endpointsCache!!
}
override fun configCustomizations(
codegenContext: ClientCodegenContext,
baseCustomizations: List<ConfigCustomization>
): List<ConfigCustomization> {
return baseCustomizations + EndpointConfigCustomization(codegenContext, endpoints)
return baseCustomizations + EndpointConfigCustomization(codegenContext, endpoints(SdkSettings.from(codegenContext.settings)))
}
override fun operationCustomizations(

View File

@ -7,6 +7,8 @@ package software.amazon.smithy.rustsdk
import software.amazon.smithy.model.node.ObjectNode
import software.amazon.smithy.rust.codegen.smithy.CoreRustSettings
import software.amazon.smithy.rust.codegen.util.orNull
import java.nio.file.Path
import java.nio.file.Paths
/**
* SDK-specific settings within the Rust codegen `customizationConfig.awsSdk` object.
@ -17,6 +19,20 @@ class SdkSettings private constructor(private val awsSdk: ObjectNode?) {
SdkSettings(coreRustSettings.customizationConfig?.getObjectMember("awsSdk")?.orNull())
}
/** Path to the `sdk-default-configuration.json` config file */
val defaultsConfigPath: Path get() =
Paths.get(
awsSdk?.getStringMember("defaultConfigPath")?.orNull()?.value
?: throw IllegalStateException("missing defaultConfigPath property")
)
/** Path to the `sdk-endpoints.json` configuration */
val endpointsConfigPath: Path get() =
Paths.get(
awsSdk?.getStringMember("endpointsConfigPath")?.orNull()?.value
?: throw IllegalStateException("missing endpointsConfigPath property")
)
/** Path to AWS SDK integration tests */
val integrationTestPath: String get() =
awsSdk?.getStringMember("integrationTestPath")?.orNull()?.value ?: "aws/sdk/integration-tests"

View File

@ -0,0 +1,55 @@
{
"version": 1,
"base": {
"retryMode": "standard",
"stsRegionalEndpoints": "regional",
"s3UsEast1RegionalEndpoints": "regional",
"connectTimeoutInMillis": 1100,
"tlsNegotiationTimeoutInMillis": 1100
},
"modes": {
"standard": {
"connectTimeoutInMillis": {
"override": 3100
},
"tlsNegotiationTimeoutInMillis": {
"override": 3100
}
},
"in-region": {
},
"cross-region": {
"connectTimeoutInMillis": {
"override": 3100
},
"tlsNegotiationTimeoutInMillis": {
"override": 3100
}
},
"mobile": {
"connectTimeoutInMillis": {
"override": 30000
},
"tlsNegotiationTimeoutInMillis": {
"override": 30000
}
}
},
"documentation": {
"modes": {
"standard": "<p>The STANDARD mode provides the latest recommended default values that should be safe to run in most scenarios</p><p>Note that the default values vended from this mode might change as best practices may evolve. As a result, it is encouraged to perform tests when upgrading the SDK</p>",
"in-region": "<p>The IN_REGION mode builds on the standard mode and includes optimization tailored for applications which call AWS services from within the same AWS region</p><p>Note that the default values vended from this mode might change as best practices may evolve. As a result, it is encouraged to perform tests when upgrading the SDK</p>",
"cross-region": "<p>The CROSS_REGION mode builds on the standard mode and includes optimization tailored for applications which call AWS services in a different region</p><p>Note that the default values vended from this mode might change as best practices may evolve. As a result, it is encouraged to perform tests when upgrading the SDK</p>",
"mobile": "<p>The MOBILE mode builds on the standard mode and includes optimization tailored for mobile applications</p><p>Note that the default values vended from this mode might change as best practices may evolve. As a result, it is encouraged to perform tests when upgrading the SDK</p>",
"auto": "<p>The AUTO mode is an experimental mode that builds on the standard mode. The SDK will attempt to discover the execution environment to determine the appropriate settings automatically.</p><p>Note that the auto detection is heuristics-based and does not guarantee 100% accuracy. STANDARD mode will be used if the execution environment cannot be determined. The auto detection might query <a href=\"https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html\">EC2 Instance Metadata service</a>, which might introduce latency. Therefore we recommend choosing an explicit defaults_mode instead if startup latency is critical to your application</p>",
"legacy": "<p>The LEGACY mode provides default settings that vary per SDK and were used prior to establishment of defaults_mode</p>"
},
"configuration": {
"retryMode": "<p>A retry mode specifies how the SDK attempts retries. See <a href=\"https://docs.aws.amazon.com/sdkref/latest/guide/setting-global-retry_mode.html\">Retry Mode</a></p>",
"stsRegionalEndpoints": "<p>Specifies how the SDK determines the AWS service endpoint that it uses to talk to the AWS Security Token Service (AWS STS). See <a href=\"https://docs.aws.amazon.com/sdkref/latest/guide/setting-global-sts_regional_endpoints.html\">Setting STS Regional endpoints</a></p>",
"s3UsEast1RegionalEndpoints": "<p>Specifies how the SDK determines the AWS service endpoint that it uses to talk to the Amazon S3 for the us-east-1 region</p>",
"connectTimeoutInMillis": "<p>The amount of time after making an initial connection attempt on a socket, where if the client does not receive a completion of the connect handshake, the client gives up and fails the operation</p>",
"tlsNegotiationTimeoutInMillis": "<p>The maximum amount of time that a TLS handshake is allowed to take from the time the CLIENT HELLO message is sent to ethe time the client and server have fully negotiated ciphers and exchanged keys</p>"
}
}
}

View File

@ -107,6 +107,8 @@ fun generateSmithyBuild(services: AwsServices): String {
"license": "Apache-2.0",
"customizationConfig": {
"awsSdk": {
"defaultConfigPath": "${services.defaultConfigPath}",
"endpointsConfigPath": "${services.endpointsConfigPath}",
"integrationTestPath": "${project.projectDir.resolve("integration-tests")}"
}
}

View File

@ -13,7 +13,12 @@ import software.amazon.smithy.model.traits.TitleTrait
import java.io.File
import kotlin.streams.toList
class AwsServices(private val project: Project, services: List<AwsService>) {
class AwsServices(
private val project: Project,
services: List<AwsService>,
val endpointsConfigPath: File,
val defaultConfigPath: File,
) {
val services: List<AwsService>
val moduleNames: Set<String> by lazy { services.map { it.module }.toSortedSet() }
@ -123,7 +128,9 @@ fun Project.discoverServices(awsModelsPath: String?, serviceMembership: Membersh
}.also { services ->
val moduleNames = services.map { it.module }
logger.info("Final service module list: $moduleNames")
}
},
models.resolve("sdk-endpoints.json"),
models.resolve("sdk-default-configuration.json"),
)
}