Skip to content

Commit

Permalink
chore: Update to Smithy 1.39.0 (#1126)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbelkins authored Sep 26, 2023
1 parent 70244cc commit fc076b7
Show file tree
Hide file tree
Showing 16 changed files with 159 additions and 9,528 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ func addProtocolTests() {
.init(name: "GlacierTestSDK", sourcePath: "\(baseDir)/glacier"),
.init(name: "MachineLearningTestSDK", sourcePath: "\(baseDir)/machinelearning"),
.init(name: "S3TestSDK", sourcePath: "\(baseDir)/s3"),
.init(name: "aws_restjson", sourcePath: "\(baseDirLocal)/aws-restjson"),
.init(name: "rest_json_extras", sourcePath: "\(baseDirLocal)/rest_json_extras"),
.init(name: "AwsQueryExtras", sourcePath: "\(baseDirLocal)/AwsQueryExtras"),
.init(name: "Waiters", sourcePath: "\(baseDirLocal)/Waiters", testPath: "codegen/protocol-test-codegen-local/Tests"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class AWSEndpointsRuleEngine {

let crtEngine: AwsCommonRuntimeKit.EndpointsRuleEngine

public init(partitions: String, ruleSet: String) throws {
public init(partitions: String = partitionJSON, ruleSet: String) throws {
Utils.setupCRT() // ensures CRT is set up before calling the CRT endpoint rules engine
crtEngine = try AwsCommonRuntimeKit.EndpointsRuleEngine(partitions: partitions, ruleSet: ruleSet)
}
Expand Down
124 changes: 124 additions & 0 deletions Sources/Core/AWSClientRuntime/Endpoints/PartitionDefinition.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
//
// Copyright Amazon.com Inc. or its affiliates.
// All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//

import Foundation

// Partition definitions are embedded as a static resource in this project, for now.
// When Trebuchet integration is performed, partitions should be obtained from Trebuchet for every
// build instead of being loaded from a static definition.
public let partitionJSON = """
{
"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,
"implicitGlobalRegion": "us-east-1"
}
},
{
"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,
"implicitGlobalRegion": "us-gov-west-1"
}
},
{
"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,
"implicitGlobalRegion": "cn-northwest-1"
}
},
{
"id": "aws-iso",
"regionRegex": "^us\\\\-iso\\\\-\\\\w+\\\\-\\\\d+$",
"outputs": {
"name": "aws-iso",
"dnsSuffix": "c2s.ic.gov",
"supportsFIPS": true,
"supportsDualStack": false,
"dualStackDnsSuffix": "c2s.ic.gov",
"implicitGlobalRegion": "us-iso-east-1"
},
"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",
"implicitGlobalRegion": "us-isob-east-1"
},
"regions": {
"us-isob-east-1": {},
"aws-iso-b-global": {}
}
}
]
}
"""
5 changes: 3 additions & 2 deletions codegen/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ appendLibTarget(name: "S3TestSDK", path: "\(baseDir)/s3")
appendTstTarget(name: "S3TestSDKTests", path: "\(baseDir)/s3", dependency: "S3TestSDK")

//Local tests
appendLibTarget(name: "aws_restjson", path: "\(baseDirLocal)/aws-restjson")
appendTstTarget(name: "aws_restjsonTests", path: "\(baseDirLocal)/aws-restjson", dependency: "aws_restjson")
appendLibTarget(name: "rest_json_extras", path: "\(baseDirLocal)/rest_json_extras")
appendTstTarget(name: "rest_json_extrasTests", path: "\(baseDirLocal)/rest_json_extras", dependency: "rest_json_extras")
appendLibTarget(name: "AwsQueryExtras", path: "\(baseDirLocal)/AwsQueryExtras")
appendTstTarget(name: "AwsQueryExtrasTests", path: "\(baseDirLocal)/AwsQueryExtras", dependency: "AwsQueryExtras")
appendLibTarget(name: "EventStream", path: "\(baseDirLocal)/EventStream")
// EventStream has a Smithy definition, but no tests defined yet.
//appendTstTarget(name: "EventStreamTests", path: "\(baseDirLocal)/EventStream", dependency: "EventStream")
appendLibTarget(name: "Waiters", path: "\(baseDirLocal)/Waiters")
appendTstTarget(name: "WaitersTests", path: "./protocol-test-codegen-local/Tests", dependency: "Waiters")

Expand Down
4 changes: 0 additions & 4 deletions codegen/protocol-test-codegen-local/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ dependencies {

data class CodegenTest(val service: String, val module: String, val extraConfig: String? = null)
val codegenTests = listOf(
CodegenTest(
"aws.protocoltests.restjson#RestJson",
"aws-restjson"
),
CodegenTest(
"aws.protocoltests.restjson#RestJsonExtras",
"rest_json_extras"
Expand Down
1 change: 1 addition & 0 deletions codegen/smithy-aws-swift-codegen/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dependencies {
testImplementation("org.junit.jupiter:junit-jupiter:$junitVersion")
testImplementation("io.kotest:kotest-assertions-core-jvm:$kotestVersion")
implementation("software.amazon.smithy:smithy-rules-engine:$smithyVersion")
implementation("software.amazon.smithy:smithy-aws-endpoints:$smithyVersion")
}

jacoco {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fun Parameter.toSymbol(): Symbol {
builder = builder.boxed()
}

defaultValue.ifPresent { defaultValue ->
default.ifPresent { defaultValue ->
builder.defaultValue(defaultValue.toString())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import software.amazon.smithy.aws.swift.codegen.middleware.EndpointResolverMiddl
import software.amazon.smithy.codegen.core.Symbol
import software.amazon.smithy.model.node.Node
import software.amazon.smithy.rulesengine.language.EndpointRuleSet
import software.amazon.smithy.rulesengine.language.stdlib.partition.DefaultPartitionDataProvider
import software.amazon.smithy.rulesengine.traits.EndpointRuleSetTrait
import software.amazon.smithy.swift.codegen.ClientRuntimeTypes
import software.amazon.smithy.swift.codegen.MiddlewareGenerator
Expand All @@ -20,7 +19,7 @@ import software.amazon.smithy.swift.codegen.model.getTrait
import software.amazon.smithy.swift.codegen.utils.toLowerCamelCase

/**
* Generates a per/service endpoint resolver (internal to the generated SDK) using endpoints.json
* Generates a per/service endpoint resolver (internal to the generated SDK)
*/
class EndpointResolverGenerator() {
fun render(ctx: ProtocolGenerator.GenerationContext) {
Expand Down Expand Up @@ -59,14 +58,12 @@ class EndpointResolverGenerator() {
writer.write("")
endpointRules?.let {
writer.write("private let engine: \$L", AWSClientRuntimeTypes.Core.AWSEndpointsRuleEngine)
val partitions = DefaultPartitionDataProvider::class.java.getResourceAsStream("/software/amazon/smithy/rulesengine/language/partitions.json")
writer.write("private let partitions = \$S", Node.printJson(Node.parse(partitions)))
writer.write("private let ruleSet = \$S", Node.printJson(endpointRules.toNode()))
}
writer.write("")
writer.openBlock("public init() throws {", "}") {
endpointRules?.let {
writer.write("engine = try \$L(partitions: partitions, ruleSet: ruleSet)", AWSClientRuntimeTypes.Core.AWSEndpointsRuleEngine)
writer.write("engine = try \$L(ruleSet: ruleSet)", AWSClientRuntimeTypes.Core.AWSEndpointsRuleEngine)
}
}
writer.write("")
Expand All @@ -75,7 +72,7 @@ class EndpointResolverGenerator() {
) {
endpointRules?.let {
writer.write("let context = try \$L()", AWSClientRuntimeTypes.Core.AWSEndpointsRequestContext)
endpointRules?.parameters?.toList()?.sortedBy { it.name.toString() }?.let { sortedParameters ->
endpointRules.parameters?.toList()?.sortedBy { it.name.toString() }?.let { sortedParameters ->
sortedParameters.forEach { param ->
val memberName = param.name.toString().toLowerCamelCase()
val paramName = param.name.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ package software.amazon.smithy.aws.swift.codegen
import software.amazon.smithy.codegen.core.CodegenException
import software.amazon.smithy.model.node.Node
import software.amazon.smithy.rulesengine.language.EndpointRuleSet
import software.amazon.smithy.rulesengine.language.eval.Value
import software.amazon.smithy.rulesengine.language.evaluation.value.ArrayValue
import software.amazon.smithy.rulesengine.language.evaluation.value.BooleanValue
import software.amazon.smithy.rulesengine.language.evaluation.value.EmptyValue
import software.amazon.smithy.rulesengine.language.evaluation.value.IntegerValue
import software.amazon.smithy.rulesengine.language.evaluation.value.RecordValue
import software.amazon.smithy.rulesengine.language.evaluation.value.StringValue
import software.amazon.smithy.rulesengine.language.evaluation.value.Value
import software.amazon.smithy.rulesengine.traits.EndpointTestsTrait
import software.amazon.smithy.swift.codegen.ClientRuntimeTypes
import software.amazon.smithy.swift.codegen.SwiftDependency
Expand Down Expand Up @@ -136,23 +142,23 @@ class EndpointTestGenerator(
*/
private fun generateValue(writer: SwiftWriter, value: Value, delimeter: String) {
when (value) {
is Value.String -> {
writer.write("\$S$delimeter", value.value())
is StringValue -> {
writer.write("\$S$delimeter", value.toString())
}

is Value.Integer -> {
is IntegerValue -> {
writer.write("\$L$delimeter", value.toString())
}

is Value.Bool -> {
is BooleanValue -> {
writer.write("\$L$delimeter", value.toString())
}

is Value.None -> {
is EmptyValue -> {
writer.write("nil$delimeter")
}

is Value.Array -> {
is ArrayValue -> {
writer.openBlock("[", "] as [AnyHashable]$delimeter") {
value.values.forEachIndexed { idx, item ->
writer.call {
Expand All @@ -162,7 +168,7 @@ class EndpointTestGenerator(
}
}

is Value.Record -> {
is RecordValue -> {
if (value.value.isEmpty()) {
writer.writeInline("[:]")
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class OperationEndpointResolverMiddleware(
}
clientContextParam != null -> {
when {
param.defaultValue.isPresent -> {
param.default.isPresent -> {
"config.serviceSpecific.${param.name.toString().toLowerCamelCase()} ?? ${param.defaultValueLiteral}"
}
else -> {
Expand All @@ -119,7 +119,7 @@ class OperationEndpointResolverMiddleware(
return when {
param.isRequired -> {
when {
param.defaultValue.isPresent -> {
param.default.isPresent -> {
"config.${param.name.toString().toLowerCamelCase()} ?? ${param.defaultValueLiteral}"
}
else -> {
Expand All @@ -131,7 +131,7 @@ class OperationEndpointResolverMiddleware(
}
}
}
param.defaultValue.isPresent -> {
param.default.isPresent -> {
"config.${param.name.toString().toLowerCamelCase()} ?? ${param.defaultValueLiteral}"
}
else -> {
Expand All @@ -150,7 +150,7 @@ class OperationEndpointResolverMiddleware(
private val Parameter.defaultValueLiteral: String
get() {
return when (type) {
ParameterType.BOOLEAN -> defaultValue.get().toString()
ParameterType.STRING -> "\"${defaultValue.get()}\""
ParameterType.BOOLEAN -> default.get().toString()
ParameterType.STRING -> "\"${default.get()}\""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class AWSRestJson1ProtocolGenerator : AWSHttpBindingProtocolGenerator() {
override val serdeContext = serdeContextJSON
override val testsToIgnore = setOf(
"SDKAppliedContentEncoding_restJson1",
"SDKAppendedGzipAfterProvidedEncoding_restJson1"
"SDKAppendedGzipAfterProvidedEncoding_restJson1",
"RestJsonHttpPayloadWithUnsetUnion"
)

override fun generateMessageMarshallable(ctx: ProtocolGenerator.GenerationContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ class RestXmlProtocolGenerator : AWSHttpBindingProtocolGenerator() {
"S3EscapeObjectKeyInUriLabel",
"S3EscapePathObjectKeyInUriLabel",
"SDKAppliedContentEncoding_restXml",
"SDKAppendedGzipAfterProvidedEncoding_restXml"
"SDKAppendedGzipAfterProvidedEncoding_restXml",
"S3OperationNoErrorWrappingResponse"
)

override fun renderStructEncode(
Expand Down
Loading

0 comments on commit fc076b7

Please sign in to comment.