From 6fb5969d1e09970f246e22d5bd319f0b0255ab66 Mon Sep 17 00:00:00 2001 From: Sichan Yoo Date: Tue, 24 Sep 2024 17:03:22 -0700 Subject: [PATCH 1/2] Write the new current version to AWSClientRuntime/Resources/sdk-version.txt as well, and use that to initialize user agent middleware during runtime. --- .../Subcommands/PrepareRelease.swift | 8 ++++++++ .../Middlewares/UserAgentMiddleware.swift | 3 +-- .../AWSClientRuntime/Resources/sdk-version.txt | 1 + .../UserAgent/CurrentSDKVersion.swift | 15 +++++++++++++++ .../codegen/middleware/UserAgentMiddleware.kt | 5 +---- 5 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 Sources/Core/AWSClientRuntime/Sources/AWSClientRuntime/Resources/sdk-version.txt create mode 100644 Sources/Core/AWSClientRuntime/Sources/AWSClientRuntime/UserAgent/CurrentSDKVersion.swift diff --git a/AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Commands/AWSSDKSwiftCLI/Subcommands/PrepareRelease.swift b/AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Commands/AWSSDKSwiftCLI/Subcommands/PrepareRelease.swift index f53b6841f05..903c450a1d1 100644 --- a/AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Commands/AWSSDKSwiftCLI/Subcommands/PrepareRelease.swift +++ b/AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Commands/AWSSDKSwiftCLI/Subcommands/PrepareRelease.swift @@ -165,6 +165,14 @@ struct PrepareRelease { do { try "\(newVersion)".write(toFile: "Package.version" , atomically: true, encoding: .utf8) log("Updated Package.version: \(newVersion)") + if (repoType == .awsSdkSwift) { + try "\(newVersion)".write( + toFile: "Sources/Core/AWSClientRuntime/Sources/AWSClientRuntime/Resources/sdk-version.txt", + atomically: true, + encoding: .utf8 + ) + log("Updated AWSClientRuntime/Resources/Package.version: \(newVersion)") + } } catch { throw Error("Failed to write version \(newVersion) to Package.version") } diff --git a/Sources/Core/AWSClientRuntime/Sources/AWSClientRuntime/Middlewares/UserAgentMiddleware.swift b/Sources/Core/AWSClientRuntime/Sources/AWSClientRuntime/Middlewares/UserAgentMiddleware.swift index 21eb9de13a9..737dd2bd265 100644 --- a/Sources/Core/AWSClientRuntime/Sources/AWSClientRuntime/Middlewares/UserAgentMiddleware.swift +++ b/Sources/Core/AWSClientRuntime/Sources/AWSClientRuntime/Middlewares/UserAgentMiddleware.swift @@ -21,11 +21,10 @@ public struct UserAgentMiddleware { public init( serviceID: String, - version: String, config: DefaultClientConfiguration & AWSDefaultClientConfiguration ) { self.serviceID = serviceID - self.version = version + self.version = sdkVersion self.config = config } } diff --git a/Sources/Core/AWSClientRuntime/Sources/AWSClientRuntime/Resources/sdk-version.txt b/Sources/Core/AWSClientRuntime/Sources/AWSClientRuntime/Resources/sdk-version.txt new file mode 100644 index 00000000000..1464c521f9e --- /dev/null +++ b/Sources/Core/AWSClientRuntime/Sources/AWSClientRuntime/Resources/sdk-version.txt @@ -0,0 +1 @@ +1.0.5 \ No newline at end of file diff --git a/Sources/Core/AWSClientRuntime/Sources/AWSClientRuntime/UserAgent/CurrentSDKVersion.swift b/Sources/Core/AWSClientRuntime/Sources/AWSClientRuntime/UserAgent/CurrentSDKVersion.swift new file mode 100644 index 00000000000..d91e6145d03 --- /dev/null +++ b/Sources/Core/AWSClientRuntime/Sources/AWSClientRuntime/UserAgent/CurrentSDKVersion.swift @@ -0,0 +1,15 @@ +// +// Copyright Amazon.com Inc. or its affiliates. +// All Rights Reserved. +// +// SPDX-License-Identifier: Apache-2.0 +// + +import Foundation + +// SDK guarantees sdk-version.txt will be present +let sdkVersionFile = Bundle.module.url(forResource: "sdk-version", withExtension: "txt")! + +// First-time load will take longer but subsequent calls will use cached data +// swiftlint:disable:next force_try +public let sdkVersion = try! String(contentsOf: sdkVersionFile, encoding: .utf8) 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..9c9548d39a7 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 @@ -34,9 +34,6 @@ class UserAgentMiddleware(val settings: SwiftSettings) : MiddlewareRenderable { } private fun middlewareParamsString(writer: SwiftWriter): String { - return writer.format( - "serviceID: serviceName, version: \$S, config: config", - settings.moduleVersion, - ) + return writer.format("serviceID: serviceName, config: config") } } From 0a22b360fcb0db0e942e18e9812b617a829c8206 Mon Sep 17 00:00:00 2001 From: Sichan Yoo Date: Wed, 25 Sep 2024 09:17:59 -0700 Subject: [PATCH 2/2] Update codegen tests --- .../smithy/aws/swift/codegen/PresignerGeneratorTests.kt | 8 ++++---- .../swift/codegen/awsquery/AWSQueryOperationStackTest.kt | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) 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..3f71b381a62 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, 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, 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, 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, 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..54ba2b28e87 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,7 +38,7 @@ 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, 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())