Unverified Commit c220b03a authored by John DiSanti's avatar John DiSanti Committed by GitHub
Browse files

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

parent bbdde4bb
Loading
Loading
Loading
Loading
+10 −4
Original line number Diff line number Diff line
@@ -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(
+16 −0
Original line number Diff line number Diff line
@@ -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"
+55 −0
Original line number Diff line number Diff line
{
  "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>"
    }
  }
}
+2 −0
Original line number Diff line number Diff line
@@ -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")}"
                            }
                        }
Loading