Commit 255be4aa authored by Russell Cohen's avatar Russell Cohen
Browse files

Source sdk-partitions from the models instead of hardcoding

1. Update `sync-models` to sync from aws-sdk-rust. This location includes `sdk-partitions.json`
2. Update aws:sdk gradle file to properly set this variable in codegen./
3. Add an additional safeguard to ensure that the default hardcoded version is only used in tests and adhoc SDK generation.
parent 1bb0349e
Loading
Loading
Loading
Loading
+3 −5
Original line number Diff line number Diff line
@@ -25,16 +25,14 @@ 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 productionSdkBuild: Boolean
        get() = awsSdk?.getBooleanMember("productionSdkBuild")?.orNull()?.value ?: false

    /** Path to AWS SDK integration tests */
    val integrationTestPath: String
        get() =
+12 −8
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

@@ -29,13 +30,16 @@ class AwsEndpointsStdLib() : ClientCodegenDecorator {

    private fun partitionMetadata(sdkSettings: SdkSettings): ObjectNode {
        if (partitionsCache == null) {
            val partitionsJson =
                when (val path = sdkSettings.partitionsConfigPath) {
                    null ->
            val partitionsJson = when (val path = sdkSettings.partitionsConfigPath) {
                null -> {
                    if (sdkSettings.productionSdkBuild) {
                        PANIC("cannot use hardcoded partitions in AWS SDK production build")
                    }
                    (
                        javaClass.getResource("/default-partitions.json")
                            ?: throw IllegalStateException("Failed to find default-partitions.json in the JAR")
                        ).readText()
                }

                else -> path.readText()
            }
+1 −105
Original line number Diff line number Diff line
{
  "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": {}
      }
    }
  ]
}
+1 −105
Original line number Diff line number Diff line
../../../../sdk/aws-models/sdk-partitions.json
 No newline at end of file
+0 −44
Original line number Diff line number Diff line
{
  "partitions" : [
    {
      "defaults": {
        "hostname": "{service}.{region}.{dnsSuffix}",
        "protocols": [
          "https"
        ],
        "signatureVersions": [
          "v4"
        ],
        "variants": [
          {
            "dnsSuffix": "amazonaws.com",
            "hostname": "{service}-fips.{region}.{dnsSuffix}",
            "tags": [
              "fips"
            ]
          },
          {
            "dnsSuffix": "api.aws",
            "hostname": "{service}-fips.{region}.{dnsSuffix}",
            "tags": [
              "dualstack",
              "fips"
            ]
          },
          {
            "dnsSuffix": "api.aws",
            "hostname": "{service}.{region}.{dnsSuffix}",
            "tags": [
              "dualstack"
            ]
          }
        ]
      },
      "dnsSuffix": "amazonaws.com",
      "partition": "aws",
      "partitionName": "AWS Standard",
      "regionRegex": "^(us|eu|ap|sa|ca|me|af)\\-\\w+\\-\\d+$"
    }
  ],
  "version" : 3
}
Loading