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

Upgrade to Smithy 1.27.2 (#2226)

* Upgrade to Smithy 1.27.1

* Fix bugs exposed by 1.27.1

* Fix rules engine customization

* update rfc3339 parsing test

* refactor timestamp format & remove upstreamed test

* Update changelog

* rename test

* fix datetime parsing on server and clients

* fix up a few more failing tests

* precommit lints

* Fix bad merge
parent 61934da0
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -288,6 +288,20 @@ references = ["smithy-rs#2448"]
meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "client" }
author = "jdisanti"


[[smithy-rs]]
message = "Fix bug in timestamp format resolution. Prior to this fix, the timestamp format may have been incorrect if set on the target instead of on the member."
references = ["smithy-rs#2226"]
meta = { "breaking" = false, "tada" = false, "bug" = true, "target" = "all" }
author = "rcoh"

[[smithy-rs]]
message = "Add support for offsets when parsing datetimes. RFC3339 date times now support offsets like `-0200`"
references = ["smithy-rs#2226"]
meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "all" }
author = "rcoh"


[[aws-sdk-rust]]
message = """Reconnect on transient errors.

+11 −73
Original line number Diff line number Diff line
@@ -10,8 +10,8 @@ import software.amazon.smithy.model.Model
import software.amazon.smithy.model.shapes.ServiceShape
import software.amazon.smithy.model.shapes.ShapeId
import software.amazon.smithy.model.transform.ModelTransformer
import software.amazon.smithy.rulesengine.language.EndpointRuleSet
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.Parameters
import software.amazon.smithy.rulesengine.traits.EndpointRuleSetTrait
import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext
@@ -21,13 +21,10 @@ import software.amazon.smithy.rust.codegen.client.smithy.endpoint.EndpointTypesG
import software.amazon.smithy.rust.codegen.client.smithy.featureGatedConfigModule
import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ConfigCustomization
import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ServiceConfig
import software.amazon.smithy.rust.codegen.core.rustlang.Attribute
import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency
import software.amazon.smithy.rust.codegen.core.rustlang.Writable
import software.amazon.smithy.rust.codegen.core.rustlang.rust
import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate
import software.amazon.smithy.rust.codegen.core.rustlang.writable
import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext
import software.amazon.smithy.rust.codegen.core.smithy.RustCrate
import software.amazon.smithy.rust.codegen.core.smithy.customize.AdHocCustomization
import software.amazon.smithy.rust.codegen.core.smithy.customize.adhocCustomization
@@ -55,24 +52,18 @@ class AwsEndpointDecorator : ClientCodegenDecorator {
        return ModelTransformer.create().mapTraits(model) { _, trait ->
            when (trait) {
                is EndpointRuleSetTrait -> {
                    val epRules = EndpointRuleSet.fromNode(trait.ruleSet)
                    val rules = trait.ruleSet.expectObjectNode()
                    val params = rules.expectObjectMember("parameters")
                    val newParameters = Parameters.builder()
                    epRules.parameters.toList()
                        .map { param ->
                    params.members.map { (key, value) ->
                        val param = Parameter.fromNode(key, value.expectObjectNode())
                        param.letIf(param.builtIn == Builtins.REGION.builtIn) { parameter ->
                                val builder = parameter.toBuilder().required(true)
                                // TODO(https://github.com/awslabs/smithy-rs/issues/2187): undo this workaround
                                parameter.defaultValue.ifPresent { default -> builder.defaultValue(default) }

                                builder.build()
                            }
                            parameter.toBuilder().required(true).build()
                        }
                        .forEach(newParameters::addParameter)

                    val newTrait = epRules.toBuilder().parameters(
                        newParameters.build(),
                    ).build()
                    EndpointRuleSetTrait.builder().ruleSet(newTrait.toNode()).build()
                    }.forEach(newParameters::addParameter)
                    EndpointRuleSetTrait.builder()
                        .ruleSet(rules.toBuilder().withMember("parameters", newParameters.build().toNode()).build())
                        .build()
                }

                else -> trait
@@ -199,59 +190,6 @@ class AwsEndpointDecorator : ClientCodegenDecorator {
            }
        }
    }

    class SdkEndpointCustomization(
        codegenContext: CodegenContext,
    ) :
        ConfigCustomization() {
        private val runtimeConfig = codegenContext.runtimeConfig
        private val resolveAwsEndpoint = AwsRuntimeType.awsEndpoint(runtimeConfig).resolve("ResolveAwsEndpoint")
        private val endpointShim = AwsRuntimeType.awsEndpoint(runtimeConfig).resolve("EndpointShim")
        private val codegenScope = arrayOf(
            "ResolveAwsEndpoint" to resolveAwsEndpoint,
            "EndpointShim" to endpointShim,
            "aws_types" to AwsRuntimeType.awsTypes(runtimeConfig),
        )

        override fun section(section: ServiceConfig): Writable = writable {
            when (section) {
                ServiceConfig.BuilderImpl -> rustTemplate(
                    """
                    /// Sets the endpoint url used to communicate with this service
                    ///
                    /// Note: this is used in combination with other endpoint rules, e.g. an API that applies a host-label prefix
                    /// will be prefixed onto this URL. To fully override the endpoint resolver, use
                    /// [`Builder::endpoint_resolver`].
                    pub fn endpoint_url(mut self, endpoint_url: impl Into<String>) -> Self {
                        self.endpoint_url = Some(endpoint_url.into());
                        self
                    }

                    /// Sets the endpoint url used to communicate with this service
                    ///
                    /// Note: this is used in combination with other endpoint rules, e.g. an API that applies a host-label prefix
                    /// will be prefixed onto this URL. To fully override the endpoint resolver, use
                    /// [`Builder::endpoint_resolver`].
                    pub fn set_endpoint_url(&mut self, endpoint_url: Option<String>) -> &mut Self {
                        self.endpoint_url = endpoint_url;
                        self
                    }
                    """,
                    *codegenScope,
                )

                ServiceConfig.BuilderBuild -> rust("endpoint_url: self.endpoint_url,")
                ServiceConfig.BuilderStruct -> rust("endpoint_url: Option<String>,")
                ServiceConfig.ConfigImpl -> {
                    Attribute.AllowDeadCode.render(this)
                    rust("pub(crate) fn endpoint_url(&self) -> Option<&str> { self.endpoint_url.as_deref() }")
                }

                ServiceConfig.ConfigStruct -> rust("endpoint_url: Option<String>,")
                else -> {}
            }
        }
    }
}

fun ClientCodegenContext.isRegionalized() = getBuiltIn(Builtins.REGION) != null
+1 −4
Original line number Diff line number Diff line
@@ -10,7 +10,6 @@ import software.amazon.smithy.rulesengine.language.EndpointRuleSet
import software.amazon.smithy.rulesengine.language.eval.Type
import software.amazon.smithy.rulesengine.language.syntax.expr.Expression
import software.amazon.smithy.rulesengine.language.syntax.expr.Reference
import software.amazon.smithy.rulesengine.language.syntax.fn.Function
import software.amazon.smithy.rulesengine.language.syntax.fn.IsSet
import software.amazon.smithy.rulesengine.language.syntax.rule.Condition
import software.amazon.smithy.rulesengine.language.syntax.rule.Rule
@@ -289,9 +288,7 @@ internal class EndpointResolverGenerator(stdlib: List<CustomRuntimeFunction>, ru
                val target = generator.generate(fn)
                val next = generateRuleInternal(rule, rest)
                when {
                    fn.type() is Type.Option ||
                        // TODO(https://github.com/awslabs/smithy/pull/1504): ReterminusCore bug: substring should return `Option<String>`:
                        (fn as Function).name == "substring" -> {
                    fn.type() is Type.Option -> {
                        Attribute.AllowUnusedVariables.render(this)
                        rustTemplate(
                            "if let Some($resultName) = #{target:W} { #{next:W} }",
+2 −2
Original line number Diff line number Diff line
@@ -273,7 +273,7 @@ class RequestBindingGenerator(
            target.isTimestampShape -> {
                val timestampFormat =
                    index.determineTimestampFormat(member, HttpBinding.Location.QUERY, protocol.defaultTimestampFormat)
                val timestampFormatType = RuntimeType.timestampFormat(runtimeConfig, timestampFormat)
                val timestampFormatType = RuntimeType.serializeTimestampFormat(runtimeConfig, timestampFormat)
                val func = writer.format(RuntimeType.queryFormat(runtimeConfig, "fmt_timestamp"))
                "&$func($targetName, ${writer.format(timestampFormatType)})?"
            }
@@ -314,7 +314,7 @@ class RequestBindingGenerator(
            target.isTimestampShape -> {
                val timestampFormat =
                    index.determineTimestampFormat(member, HttpBinding.Location.LABEL, protocol.defaultTimestampFormat)
                val timestampFormatType = RuntimeType.timestampFormat(runtimeConfig, timestampFormat)
                val timestampFormatType = RuntimeType.serializeTimestampFormat(runtimeConfig, timestampFormat)
                val func = format(RuntimeType.labelFormat(runtimeConfig, "fmt_timestamp"))
                rust("let $outputVar = $func($input, ${format(timestampFormatType)})?;")
            }
+0 −662

File deleted.

Preview size limit exceeded, changes collapsed.

Loading