diff --git a/AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Resources/Package.Base.txt b/AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Resources/Package.Base.txt index dd7afe70594..56028fa8da4 100644 --- a/AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Resources/Package.Base.txt +++ b/AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Resources/Package.Base.txt @@ -189,8 +189,7 @@ private func target(_ service: String) -> Target { .awsSDKEventStreamsAuth, .awsSDKChecksums, ], - path: "Sources/Services/\(service)/Sources/\(service)", - resources: [.process("Resources")] + path: "Sources/Services/\(service)/Sources/\(service)" ) } diff --git a/Package.swift b/Package.swift index d489403c67b..728fdf92891 100644 --- a/Package.swift +++ b/Package.swift @@ -603,8 +603,7 @@ private func target(_ service: String) -> Target { .awsSDKEventStreamsAuth, .awsSDKChecksums, ], - path: "Sources/Services/\(service)/Sources/\(service)", - resources: [.process("Resources")] + path: "Sources/Services/\(service)/Sources/\(service)" ) } diff --git a/ServiceClientVersions.json b/ServiceClientVersions.json deleted file mode 100644 index 3300e0601f0..00000000000 --- a/ServiceClientVersions.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "sdk": "1.0" -} diff --git a/codegen/sdk-codegen/build.gradle.kts b/codegen/sdk-codegen/build.gradle.kts index 34e88492b94..56e67030113 100644 --- a/codegen/sdk-codegen/build.gradle.kts +++ b/codegen/sdk-codegen/build.gradle.kts @@ -6,10 +6,8 @@ // This build file has been adapted from the Go v2 SDK, here: // https://github.com/aws/aws-sdk-go-v2/blob/master/codegen/sdk-codegen/build.gradle.kts -import org.jetbrains.kotlin.com.google.common.primitives.Chars import software.amazon.smithy.gradle.tasks.SmithyBuild import software.amazon.smithy.model.Model -import software.amazon.smithy.model.node.Node import software.amazon.smithy.model.shapes.ServiceShape import java.nio.charset.Charset import java.util.Properties @@ -65,20 +63,6 @@ fun getProperty(name: String): String? { return null } -// TODO: Update this list with more services (currently just services with integration tests) -val interceptorsServices = setOf( - "AWSCloudFrontKeyValueStore", - "AWSEC2", - "AWSECS", - "AWSEventBridge", - "AWSKinesis", - "AWSMediaConvert", - "AWSRoute53", - "AWSS3", - "AWSSQS", - "AWSTranscribeStreaming", -) - // Represents information needed to generate a smithy projection JSON stanza data class AwsService( val name: String, @@ -97,7 +81,6 @@ fun generateSmithyBuild(services: List): String { require(services.isNotEmpty()) { "No services discovered. Verify aws.services and aws.protocols properties in local.build. Aborting." } - val buildStandaloneSdk = getProperty("buildStandaloneSdk")?.toBoolean() ?: false val projections = services.joinToString(",") { service -> // escape windows paths for valid json val absModelPath = service.modelFile.absolutePath.replace("\\", "\\\\") @@ -119,9 +102,6 @@ fun generateSmithyBuild(services: List): String { "author": "Amazon Web Services", "gitRepo": "${service.gitRepo}", "swiftVersion": "5.9.0", - "build": { - "rootProject": $buildStandaloneSdk - }, "mergeModels": true, "copyrightNotice": "//\n// Copyright Amazon.com Inc. or its affiliates.\n// All Rights Reserved.\n//\n// SPDX-License-Identifier: Apache-2.0\n//\n\n// Code generated by smithy-swift-codegen. DO NOT EDIT!\n\n" } @@ -160,24 +140,22 @@ fun discoverServices(): List { return filteredModels .map { file -> - val model = Model.assembler().addImport(file.absolutePath).assemble().result.get() - val services: List = model.shapes(ServiceShape::class.java).sorted().toList() - require(services.size == 1) { "Expected one service per aws model, but found ${services.size} in ${file.absolutePath}: ${services.map { it.id }}" } - val service = services.first() - file to service - }.map{ (file, service) -> + val model = Model.assembler().addImport(file.absolutePath).assemble().result.get() + val services: List = model.shapes(ServiceShape::class.java).sorted().toList() + require(services.size == 1) { "Expected one service per aws model, but found ${services.size} in ${file.absolutePath}: ${services.map { it.id }}" } + val service = services.first() + file to service + }.map { (file, service) -> val serviceApi = service.getTrait(software.amazon.smithy.aws.traits.ServiceTrait::class.java).orNull() ?: error { "Expected aws.api#service trait attached to model ${file.absolutePath}" } val (name, version, _) = file.name.split(".") - val serviceClientVersions = Node.parse(rootProject.file("ServiceClientVersions.json").readText(Charset.forName("UTF-8"))) - val packageVersion = serviceClientVersions.expectObjectNode().getStringMember(name).orNull()?.value ?: - serviceClientVersions.expectObjectNode().getStringMember("sdk").get().value + val packageName = "AWS${serviceApi.sdkId.filterNot { it.isWhitespace() }.capitalize()}" logger.info("discovered service: ${serviceApi.sdkId}") AwsService( name = service.id.toString(), - packageName = "AWS${serviceApi.sdkId.filterNot { it.isWhitespace() }.capitalize()}", + packageName = packageName, packageVersion = packageVersion, modelFile = file, projectionName = name + "." + version.toLowerCase(), @@ -187,6 +165,8 @@ fun discoverServices(): List { } val discoveredServices: List by lazy { discoverServices() } +val packageVersion = rootProject.file("Package.version.next").readText(Charset.forName("UTF-8")).trim() + val AwsService.outputDir: String get() = project.file("${project.buildDir}/smithyprojections/${project.name}/${projectionName}/swift-codegen").absolutePath diff --git a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/middleware/UserAgentMiddleware.kt b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/middleware/UserAgentMiddleware.kt index 3360068fc9f..37e667674a2 100644 --- a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/middleware/UserAgentMiddleware.kt +++ b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/middleware/UserAgentMiddleware.kt @@ -22,21 +22,14 @@ class UserAgentMiddleware(val settings: SwiftSettings) : MiddlewareRenderable { writer: SwiftWriter, op: OperationShape ) { - val params = middlewareParamsString(writer) val input = MiddlewareShapeUtils.inputSymbol(ctx.symbolProvider, ctx.model, op) val output = MiddlewareShapeUtils.outputSymbol(ctx.symbolProvider, ctx.model, op) writer.write( - "\$N<\$N, \$N>($params)", + "\$N<\$N, \$N>(serviceID: serviceName, version: \$L.version, config: config)", AWSClientRuntimeTypes.Core.UserAgentMiddleware, input, - output - ) - } - - private fun middlewareParamsString(writer: SwiftWriter): String { - return writer.format( - "serviceID: serviceName, version: \$S, config: config", - settings.moduleVersion, + output, + ctx.symbolProvider.toSymbol(ctx.service).name, ) } } diff --git a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/swiftintegrations/PackageVersionIntegration.kt b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/swiftintegrations/PackageVersionIntegration.kt deleted file mode 100644 index fb16f7820b7..00000000000 --- a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/swiftintegrations/PackageVersionIntegration.kt +++ /dev/null @@ -1,24 +0,0 @@ -package software.amazon.smithy.aws.swift.codegen.swiftintegrations - -import software.amazon.smithy.model.Model -import software.amazon.smithy.swift.codegen.SwiftDelegator -import software.amazon.smithy.swift.codegen.SwiftSettings -import software.amazon.smithy.swift.codegen.core.SwiftCodegenContext -import software.amazon.smithy.swift.codegen.integration.ProtocolGenerator -import software.amazon.smithy.swift.codegen.integration.SwiftIntegration - -class PackageVersionIntegration : SwiftIntegration { - - override fun enabledForService(model: Model, settings: SwiftSettings): Boolean = true - - override fun writeAdditionalFiles( - ctx: SwiftCodegenContext, - protocolGenerationContext: ProtocolGenerator.GenerationContext, - delegator: SwiftDelegator - ) { - val path = "Sources/${ctx.settings.moduleName}/Resources/Package.version" - protocolGenerationContext.delegator.useFileWriter(path) { writer -> - writer.writeInline(ctx.settings.moduleVersion) - } - } -} diff --git a/codegen/smithy-aws-swift-codegen/src/main/resources/META-INF/services/software.amazon.smithy.swift.codegen.integration.SwiftIntegration b/codegen/smithy-aws-swift-codegen/src/main/resources/META-INF/services/software.amazon.smithy.swift.codegen.integration.SwiftIntegration index e1f99b65c66..f65caf867fb 100644 --- a/codegen/smithy-aws-swift-codegen/src/main/resources/META-INF/services/software.amazon.smithy.swift.codegen.integration.SwiftIntegration +++ b/codegen/smithy-aws-swift-codegen/src/main/resources/META-INF/services/software.amazon.smithy.swift.codegen.integration.SwiftIntegration @@ -25,5 +25,4 @@ software.amazon.smithy.aws.swift.codegen.model.AWSDeprecatedShapeRemover software.amazon.smithy.aws.swift.codegen.AWSClientConfigurationIntegration software.amazon.smithy.swift.codegen.swiftintegrations.InitialRequestIntegration software.amazon.smithy.aws.swift.codegen.swiftintegrations.RegistryConfigIntegration -software.amazon.smithy.aws.swift.codegen.swiftintegrations.PackageVersionIntegration software.amazon.smithy.aws.swift.codegen.swiftintegrations.AmzSdkRetryHeadersIntegration diff --git a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/PresignerGeneratorTests.kt b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/PresignerGeneratorTests.kt index 7d63cd5e313..eb8d48e3009 100644 --- a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/PresignerGeneratorTests.kt +++ b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/PresignerGeneratorTests.kt @@ -55,7 +55,7 @@ extension GetFooInput { builder.applySigner(ClientRuntime.SignerMiddleware()) let endpointParams = EndpointParams() builder.applyEndpoint(AWSClientRuntime.EndpointResolverMiddleware(endpointResolverBlock: { [config] in try config.endpointResolver.resolve(params: ${'$'}0) }, endpointParams: endpointParams)) - builder.interceptors.add(AWSClientRuntime.UserAgentMiddleware(serviceID: serviceName, version: "1.0.0", config: config)) + builder.interceptors.add(AWSClientRuntime.UserAgentMiddleware(serviceID: serviceName, version: ExampleClient.version, config: config)) builder.selectAuthScheme(ClientRuntime.AuthSchemeMiddleware()) var metricsAttributes = Smithy.Attributes() metricsAttributes.set(key: ClientRuntime.OrchestratorMetricsAttributesKeys.service, value: "Example") @@ -127,7 +127,7 @@ extension PostFooInput { builder.applySigner(ClientRuntime.SignerMiddleware()) let endpointParams = EndpointParams() builder.applyEndpoint(AWSClientRuntime.EndpointResolverMiddleware(endpointResolverBlock: { [config] in try config.endpointResolver.resolve(params: ${'$'}0) }, endpointParams: endpointParams)) - builder.interceptors.add(AWSClientRuntime.UserAgentMiddleware(serviceID: serviceName, version: "1.0.0", config: config)) + builder.interceptors.add(AWSClientRuntime.UserAgentMiddleware(serviceID: serviceName, version: ExampleClient.version, config: config)) builder.selectAuthScheme(ClientRuntime.AuthSchemeMiddleware()) var metricsAttributes = Smithy.Attributes() metricsAttributes.set(key: ClientRuntime.OrchestratorMetricsAttributesKeys.service, value: "Example") @@ -199,7 +199,7 @@ extension PutFooInput { builder.applySigner(ClientRuntime.SignerMiddleware()) let endpointParams = EndpointParams() builder.applyEndpoint(AWSClientRuntime.EndpointResolverMiddleware(endpointResolverBlock: { [config] in try config.endpointResolver.resolve(params: ${'$'}0) }, endpointParams: endpointParams)) - builder.interceptors.add(AWSClientRuntime.UserAgentMiddleware(serviceID: serviceName, version: "1.0.0", config: config)) + builder.interceptors.add(AWSClientRuntime.UserAgentMiddleware(serviceID: serviceName, version: ExampleClient.version, config: config)) builder.selectAuthScheme(ClientRuntime.AuthSchemeMiddleware()) var metricsAttributes = Smithy.Attributes() metricsAttributes.set(key: ClientRuntime.OrchestratorMetricsAttributesKeys.service, value: "Example") @@ -272,7 +272,7 @@ extension PutObjectInput { let endpointParams = EndpointParams() context.attributes.set(key: Smithy.AttributeKey(name: "EndpointParams"), value: endpointParams) builder.applyEndpoint(AWSClientRuntime.EndpointResolverMiddleware(endpointResolverBlock: { [config] in try config.endpointResolver.resolve(params: ${'$'}0) }, endpointParams: endpointParams)) - builder.interceptors.add(AWSClientRuntime.UserAgentMiddleware(serviceID: serviceName, version: "1.0.0", config: config)) + builder.interceptors.add(AWSClientRuntime.UserAgentMiddleware(serviceID: serviceName, version: S3Client.version, config: config)) builder.selectAuthScheme(ClientRuntime.AuthSchemeMiddleware()) var metricsAttributes = Smithy.Attributes() metricsAttributes.set(key: ClientRuntime.OrchestratorMetricsAttributesKeys.service, value: "S3") diff --git a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/awsquery/AWSQueryOperationStackTest.kt b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/awsquery/AWSQueryOperationStackTest.kt index b0d24485793..2eaff2bd73c 100644 --- a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/awsquery/AWSQueryOperationStackTest.kt +++ b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/awsquery/AWSQueryOperationStackTest.kt @@ -38,10 +38,24 @@ class AWSQueryOperationStackTest { builder.applySigner(ClientRuntime.SignerMiddleware()) let endpointParams = EndpointParams() builder.applyEndpoint(AWSClientRuntime.EndpointResolverMiddleware(endpointResolverBlock: { [config] in try config.endpointResolver.resolve(params: ${'$'}0) }, endpointParams: endpointParams)) - builder.interceptors.add(AWSClientRuntime.UserAgentMiddleware(serviceID: serviceName, version: "1.0.0", config: config)) + builder.interceptors.add(AWSClientRuntime.UserAgentMiddleware(serviceID: serviceName, version: QueryProtocolClient.version, config: config)) builder.serialize(ClientRuntime.BodyMiddleware(rootNodeInfo: "", inputWritingClosure: NoInputAndOutputInput.write(value:to:))) builder.interceptors.add(ClientRuntime.ContentTypeMiddleware(contentType: "application/x-www-form-urlencoded")) builder.selectAuthScheme(ClientRuntime.AuthSchemeMiddleware()) + builder.interceptors.add(AWSClientRuntime.AmzSdkInvocationIdMiddleware()) + builder.interceptors.add(AWSClientRuntime.AmzSdkRequestMiddleware(maxRetries: config.retryStrategyOptions.maxRetriesBase)) + var metricsAttributes = Smithy.Attributes() + metricsAttributes.set(key: ClientRuntime.OrchestratorMetricsAttributesKeys.service, value: "QueryProtocol") + metricsAttributes.set(key: ClientRuntime.OrchestratorMetricsAttributesKeys.method, value: "NoInputAndOutput") + let op = builder.attributes(context) + .telemetry(ClientRuntime.OrchestratorTelemetry( + telemetryProvider: config.telemetryProvider, + metricsAttributes: metricsAttributes, + meterScope: serviceName, + tracerScope: serviceName + )) + .executeRequest(client) + .build() """ contents.shouldContainOnlyOnce(expectedContents) } diff --git a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/awsrestjson/AWSRestJson1ProtocolGeneratorTests.kt b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/awsrestjson/AWSRestJson1ProtocolGeneratorTests.kt index e32fc311c1f..ea67a957e91 100644 --- a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/awsrestjson/AWSRestJson1ProtocolGeneratorTests.kt +++ b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/awsrestjson/AWSRestJson1ProtocolGeneratorTests.kt @@ -61,6 +61,7 @@ extension ExplicitBlobInput { val expectedContents = """ public class ExampleClient: ClientRuntime.Client { public static let clientName = "ExampleClient" + public static let version = "1.0.0" let client: ClientRuntime.SdkHttpClient let config: ExampleClient.ExampleClientConfiguration let serviceName = "Example"