Unverified Commit cfd89422 authored by AWS SDK Rust Bot's avatar AWS SDK Rust Bot Committed by GitHub
Browse files

Source sdk-partitions from the models instead of hardcoding (#3292)

parents f84f9ba8 fc3ba64f
Loading
Loading
Loading
Loading
+32 −32
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@ name: Daily credentials verification
on:
  schedule:
    # Runs 00:00 UTC every day
    - cron: "0 0 * * *"
  - cron: 0 0 * * *
  workflow_dispatch:

jobs:
+6 −0
Original line number Diff line number Diff line
@@ -35,6 +35,12 @@ references = ["smithy-rs#3252", "smithy-rs#3312"]
meta = { "breaking" = false, "tada" = false, "bug" = true }
author = "milesziemer"

[[smithy-rs]]
message = """`requireEndpointResolver: false` is no longer required to remove the need for an endpoint resolver. Instead, `"awsSdkBuilder"` (default false), now _removes_ that requirement."""
references = ["smithy-rs#3292"]
meta = { "breaking" = false, "tada" = false, "bug" = false }
author = "rcoh"

[[aws-sdk-rust]]
message = "Fix bug in `CredentialsProcess` provider where `expiry` was incorrectly treated as a required field."
references = ["smithy-rs#3335", "aws-sdk-rust#1021"]
+0 −8
Original line number Diff line number Diff line
@@ -54,14 +54,6 @@ fun baseTest(service: String, module: String, imports: List<String> = listOf()):
            "includeFluentClient": false,
            "nullabilityCheckMode": "${getNullabilityCheckMode()}"
        """,
        extraConfig = """
            , "customizationConfig": {
                "awsSdk": {
                    "generateReadme": false,
                    "requireEndpointResolver": false
                }
            }
        """,
    )
}

+50 −11
Original line number Diff line number Diff line
@@ -10,14 +10,56 @@ import software.amazon.smithy.rust.codegen.core.smithy.CoreRustSettings
import software.amazon.smithy.rust.codegen.core.util.orNull
import java.nio.file.Path
import java.nio.file.Paths
import java.util.logging.Logger

/**
 * SDK-specific settings within the Rust codegen `customizationConfig.awsSdk` object.
 */
class SdkSettings private constructor(private val awsSdk: ObjectNode?) {
    private fun warnOnUnusedProperties() {
        if (awsSdk == null) {
            return
        }
        val logger = Logger.getLogger("SdkSettings")
        if (awsSdk.getMember("generateReadme").isPresent) {
            logger.warning(
                "`generateReadme` parameter is now ignored. Readmes are now only generated when " +
                    "`awsSdkBuild` is set to `true`. You can use `suppressReadme` to explicitly suppress the readme in that case.",
            )
        }

        if (awsSdk.getMember("requireEndpointResolver").isPresent) {
            logger.warning(
                "`requireEndpointResolver` is no a no-op and you may remove it from your configuration. " +
                    "An endpoint resolver is only required when `awsSdkBuild` is set to true.",
            )
        }
    }

    companion object {
        fun from(coreRustSettings: CoreRustSettings): SdkSettings =
            SdkSettings(coreRustSettings.customizationConfig?.getObjectMember("awsSdk")?.orNull())
        fun from(coreRustSettings: CoreRustSettings): SdkSettings {
            val settings = SdkSettings(coreRustSettings.customizationConfig?.getObjectMember("awsSdk")?.orNull())
            if (shouldPrintWarning()) {
                settings.warnOnUnusedProperties()
                warningPrinted()
            }
            return settings
        }

        @Volatile
        var warningPrinted = false

        private fun warningPrinted() {
            synchronized(this) {
                this.warningPrinted = true
            }
        }

        private fun shouldPrintWarning(): Boolean {
            synchronized(this) {
                return !this.warningPrinted
            }
        }
    }

    /** Path to the `sdk-default-configuration.json` config file */
@@ -25,33 +67,30 @@ class SdkSettings private constructor(private val awsSdk: ObjectNode?) {
        get() =
            awsSdk?.getStringMember("defaultConfigPath")?.orNull()?.value.let { Paths.get(it) }

    /** Path to the `sdk-endpoints.json` configuration */
    val endpointsConfigPath: Path?
        get() =
            awsSdk?.getStringMember("endpointsConfigPath")?.orNull()?.value?.let { Paths.get(it) }

    /** Path to the `default-partitions.json` configuration */
    val partitionsConfigPath: Path?
        get() =
            awsSdk?.getStringMember("partitionsConfigPath")?.orNull()?.value?.let { Paths.get(it) }

    val awsSdkBuild: Boolean
        get() = awsSdk?.getBooleanMember("awsSdkBuild")?.orNull()?.value ?: false

    /** Path to AWS SDK integration tests */
    val integrationTestPath: String
        get() =
            awsSdk?.getStringMember("integrationTestPath")?.orNull()?.value ?: "aws/sdk/integration-tests"

    /** Version number of the `aws-config` crate */
    /** Version number of the `aws-config` crate. This is used to set the dev-dependency when generating readme's  */
    val awsConfigVersion: String?
        get() =
            awsSdk?.getStringMember("awsConfigVersion")?.orNull()?.value

    /** Whether to generate a README */
    val generateReadme: Boolean
        get() =
            awsSdk?.getBooleanMember("generateReadme")?.orNull()?.value ?: false
        get() = awsSdkBuild && !(awsSdk?.getBooleanMember("suppressReadme")?.orNull()?.value ?: false)

    val requireEndpointResolver: Boolean
        get() = awsSdk?.getBooleanMember("requireEndpointResolver")?.orNull()?.value ?: true
        get() = awsSdkBuild
}

fun ClientCodegenContext.sdkSettings() = SdkSettings.from(this.settings)
+6 −1
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ import software.amazon.smithy.rust.codegen.client.smithy.customize.ClientCodegen
import software.amazon.smithy.rust.codegen.client.smithy.endpoint.EndpointCustomization
import software.amazon.smithy.rust.codegen.client.smithy.endpoint.generators.CustomRuntimeFunction
import software.amazon.smithy.rust.codegen.client.smithy.endpoint.rulesgen.awsStandardLib
import software.amazon.smithy.rust.codegen.core.util.PANIC
import software.amazon.smithy.rustsdk.SdkSettings
import kotlin.io.path.readText

@@ -31,11 +32,15 @@ class AwsEndpointsStdLib() : ClientCodegenDecorator {
        if (partitionsCache == null) {
            val partitionsJson =
                when (val path = sdkSettings.partitionsConfigPath) {
                    null ->
                    null -> {
                        if (sdkSettings.awsSdkBuild) {
                            PANIC("cannot use hardcoded partitions in AWS SDK build")
                        }
                        (
                            javaClass.getResource("/default-partitions.json")
                                ?: throw IllegalStateException("Failed to find default-partitions.json in the JAR")
                        ).readText()
                    }

                    else -> path.readText()
                }
Loading