Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Smithy 1.27.2 #2226

Merged
merged 12 commits into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CHANGELOG.next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 ->
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()
}
params.members.map { (key, value) ->
val param = Parameter.fromNode(key, value.expectObjectNode())
param.letIf(param.builtIn == Builtins.REGION.builtIn) { parameter ->
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
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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} }",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)})?"
}
Expand Down Expand Up @@ -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)})?;")
}
Expand Down
Loading