Unverified Commit 8a1f09ef authored by Russell Cohen's avatar Russell Cohen Committed by GitHub
Browse files

Update to Smithy 1.39 (#2998)



## Motivation and Context
<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here -->
Upgrade to Smithy 1.39:



## Description
<!--- Describe your changes in detail -->
The main change here is updating the endpoints generator. To get
everything building I had to make a couple of other changes:
- disable a couple of broken protocol tests
- update the models so that they pass the new, more stringent validators
- clean up some of our test models that were invalid
- delete some protocol tests that were migrated upstream

## Testing
<!--- Please describe in detail how you tested your changes -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->
CI / verify no codegen diff.
- [ ] verify no diff

## Checklist
<!--- If a checkbox below is not applicable, then please DELETE it
rather than leaving it unchecked -->
- [ ] I have updated `CHANGELOG.next.toml` if I made changes to the
smithy-rs codegen or runtime crates
- [ ] I have updated `CHANGELOG.next.toml` if I made changes to the AWS
SDK, generated SDK code, or SDK runtime crates

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._

---------

Co-authored-by: default avatarkstich <kevin@kstich.com>
parent 2b757b24
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ apply BackplaneControlService @endpointRuleSet({
                  "endpoint": { "url": "https://www.example.com" }
              }],
    "parameters": {
        "Bucket": { "required": false, "type": "String" },
        "Region": { "required": false, "type": "String", "builtIn": "AWS::Region" },
    }
})
+20 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ use smithy.rules#endpointTests
                    "authSchemes": [{
                                        "name": "sigv4",
                                        "signingRegion": "{Region}",
                                        "signingName": "blah"
                                    }]
                }
            }
@@ -33,6 +34,24 @@ use smithy.rules#endpointTests
    ]
})
@endpointTests({"version": "1", "testCases": [
    {
        "documentation": "region set",
        "expect": {
            "endpoint": {
                "url": "https://prod.us-east-1.api.myservice.aws.dev",
                "properties": {
                    "authSchemes": [{
                                        "name": "sigv4",
                                        "signingRegion": "us-east-1",
                                        "signingName": "blah"
                                    }]

                }
            }
        },
        "params": { "Region": "us-east-1" }
        "operationInputs": [ ]
    },
    {
        "documentation": "region should fallback to the default",
        "expect": {
@@ -42,6 +61,7 @@ use smithy.rules#endpointTests
                    "authSchemes": [{
                                        "name": "sigv4",
                                        "signingRegion": "us-east-2",
                                        "signingName": "blah"
                                    }]

                }
+1 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ dependencies {
    implementation("software.amazon.smithy:smithy-aws-traits:$smithyVersion")
    implementation("software.amazon.smithy:smithy-protocol-test-traits:$smithyVersion")
    implementation("software.amazon.smithy:smithy-rules-engine:$smithyVersion")
    implementation("software.amazon.smithy:smithy-aws-endpoints:$smithyVersion")
}

val generateAwsRuntimeCrateVersion by tasks.registering {
+8 −7
Original line number Diff line number Diff line
@@ -11,8 +11,9 @@ import software.amazon.smithy.model.node.Node
import software.amazon.smithy.model.node.StringNode
import software.amazon.smithy.model.shapes.ServiceShape
import software.amazon.smithy.model.shapes.ShapeId
import software.amazon.smithy.rulesengine.aws.language.functions.AwsBuiltIns
import software.amazon.smithy.rulesengine.language.EndpointRuleSet
import software.amazon.smithy.rulesengine.language.syntax.parameters.Builtins
import software.amazon.smithy.rulesengine.language.syntax.parameters.BuiltIns
import software.amazon.smithy.rulesengine.language.syntax.parameters.Parameter
import software.amazon.smithy.rulesengine.language.syntax.parameters.ParameterType
import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext
@@ -57,9 +58,9 @@ fun ClientCodegenContext.getBuiltIn(builtIn: String): Parameter? {
}

private fun promotedBuiltins(parameter: Parameter) =
    parameter.builtIn == Builtins.FIPS.builtIn ||
        parameter.builtIn == Builtins.DUALSTACK.builtIn ||
        parameter.builtIn == Builtins.SDK_ENDPOINT.builtIn
    parameter.builtIn == AwsBuiltIns.FIPS.builtIn ||
        parameter.builtIn == AwsBuiltIns.DUALSTACK.builtIn ||
        parameter.builtIn == BuiltIns.SDK_ENDPOINT.builtIn

private fun configParamNewtype(parameter: Parameter, name: String, runtimeConfig: RuntimeConfig): RuntimeType {
    val type = parameter.symbol().mapRustType { t -> t.stripOuter<RustType.Option>() }
@@ -202,10 +203,10 @@ fun Node.toWritable(): Writable {

val PromotedBuiltInsDecorators =
    listOf(
        decoratorForBuiltIn(Builtins.FIPS),
        decoratorForBuiltIn(Builtins.DUALSTACK),
        decoratorForBuiltIn(AwsBuiltIns.FIPS),
        decoratorForBuiltIn(AwsBuiltIns.DUALSTACK),
        decoratorForBuiltIn(
            Builtins.SDK_ENDPOINT,
            BuiltIns.SDK_ENDPOINT,
            ConfigParam.Builder()
                .name("endpoint_url")
                .type(RuntimeType.String.toSymbol())
+7 −4
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@ import software.amazon.smithy.aws.traits.auth.SigV4Trait
import software.amazon.smithy.model.knowledge.ServiceIndex
import software.amazon.smithy.model.node.Node
import software.amazon.smithy.model.shapes.OperationShape
import software.amazon.smithy.rulesengine.language.syntax.parameters.Builtins
import software.amazon.smithy.rulesengine.aws.language.functions.AwsBuiltIns
import software.amazon.smithy.rulesengine.language.syntax.parameters.Parameter
import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext
import software.amazon.smithy.rust.codegen.client.smithy.ClientRustModule
@@ -87,7 +87,7 @@ class RegionDecorator : ClientCodegenDecorator {
    // Services that have an endpoint ruleset that references the SDK::Region built in, or
    // that use SigV4, both need a configurable region.
    private fun usesRegion(codegenContext: ClientCodegenContext) =
        codegenContext.getBuiltIn(Builtins.REGION) != null || ServiceIndex.of(codegenContext.model)
        codegenContext.getBuiltIn(AwsBuiltIns.REGION) != null || ServiceIndex.of(codegenContext.model)
            .getEffectiveAuthSchemes(codegenContext.serviceShape).containsKey(SigV4Trait.ID)

    override fun configCustomizations(
@@ -136,7 +136,7 @@ class RegionDecorator : ClientCodegenDecorator {
            object : EndpointCustomization {
                override fun loadBuiltInFromServiceConfig(parameter: Parameter, configRef: String): Writable? {
                    return when (parameter.builtIn) {
                        Builtins.REGION.builtIn -> writable {
                        AwsBuiltIns.REGION.builtIn -> writable {
                            if (codegenContext.smithyRuntimeMode.generateOrchestrator) {
                                rustTemplate(
                                    "$configRef.load::<#{Region}>().map(|r|r.as_ref().to_owned())",
@@ -146,12 +146,13 @@ class RegionDecorator : ClientCodegenDecorator {
                                rust("$configRef.region.as_ref().map(|r|r.as_ref().to_owned())")
                            }
                        }

                        else -> null
                    }
                }

                override fun setBuiltInOnServiceConfig(name: String, value: Node, configBuilderRef: String): Writable? {
                    if (name != Builtins.REGION.builtIn.get()) {
                    if (name != AwsBuiltIns.REGION.builtIn.get()) {
                        return null
                    }
                    return writable {
@@ -174,6 +175,7 @@ class RegionProviderConfig(codegenContext: ClientCodegenContext) : ConfigCustomi
        *preludeScope,
        "Region" to region.resolve("Region"),
    )

    override fun section(section: ServiceConfig) = writable {
        when (section) {
            ServiceConfig.ConfigStruct -> {
@@ -181,6 +183,7 @@ class RegionProviderConfig(codegenContext: ClientCodegenContext) : ConfigCustomi
                    rustTemplate("pub(crate) region: #{Option}<#{Region}>,", *codegenScope)
                }
            }

            ServiceConfig.ConfigImpl -> {
                if (runtimeMode.generateOrchestrator) {
                    rustTemplate(
Loading