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

fix: Fix SDK version metadata in UserAgent header #1775

Closed
wants to merge 3 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
}
Comment on lines +168 to +175
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-Blocking: This may be the best solution but it gives me pause that we will be storing a duplicate of package.version in a sdk-version.txt. I understand the reasons for doing so but I wonder if there is either a better way or an opportunity for refactoring so that we only have a single file with the version.

} catch {
throw Error("Failed to write version \(newVersion) to Package.version")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ public struct UserAgentMiddleware<OperationStackInput, OperationStackOutput> {

public init(
serviceID: String,
version: String,
config: DefaultClientConfiguration & AWSDefaultClientConfiguration
) {
self.serviceID = serviceID
self.version = version
self.version = sdkVersion
self.config = config
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.5
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ extension GetFooInput {
builder.applySigner(ClientRuntime.SignerMiddleware<GetFooOutput>())
let endpointParams = EndpointParams()
builder.applyEndpoint(AWSClientRuntime.EndpointResolverMiddleware<GetFooOutput, EndpointParams>(endpointResolverBlock: { [config] in try config.endpointResolver.resolve(params: ${'$'}0) }, endpointParams: endpointParams))
builder.interceptors.add(AWSClientRuntime.UserAgentMiddleware<GetFooInput, GetFooOutput>(serviceID: serviceName, version: "1.0.0", config: config))
builder.interceptors.add(AWSClientRuntime.UserAgentMiddleware<GetFooInput, GetFooOutput>(serviceID: serviceName, config: config))
builder.selectAuthScheme(ClientRuntime.AuthSchemeMiddleware<GetFooOutput>())
var metricsAttributes = Smithy.Attributes()
metricsAttributes.set(key: ClientRuntime.OrchestratorMetricsAttributesKeys.service, value: "Example")
Expand Down Expand Up @@ -127,7 +127,7 @@ extension PostFooInput {
builder.applySigner(ClientRuntime.SignerMiddleware<PostFooOutput>())
let endpointParams = EndpointParams()
builder.applyEndpoint(AWSClientRuntime.EndpointResolverMiddleware<PostFooOutput, EndpointParams>(endpointResolverBlock: { [config] in try config.endpointResolver.resolve(params: ${'$'}0) }, endpointParams: endpointParams))
builder.interceptors.add(AWSClientRuntime.UserAgentMiddleware<PostFooInput, PostFooOutput>(serviceID: serviceName, version: "1.0.0", config: config))
builder.interceptors.add(AWSClientRuntime.UserAgentMiddleware<PostFooInput, PostFooOutput>(serviceID: serviceName, config: config))
builder.selectAuthScheme(ClientRuntime.AuthSchemeMiddleware<PostFooOutput>())
var metricsAttributes = Smithy.Attributes()
metricsAttributes.set(key: ClientRuntime.OrchestratorMetricsAttributesKeys.service, value: "Example")
Expand Down Expand Up @@ -199,7 +199,7 @@ extension PutFooInput {
builder.applySigner(ClientRuntime.SignerMiddleware<PutFooOutput>())
let endpointParams = EndpointParams()
builder.applyEndpoint(AWSClientRuntime.EndpointResolverMiddleware<PutFooOutput, EndpointParams>(endpointResolverBlock: { [config] in try config.endpointResolver.resolve(params: ${'$'}0) }, endpointParams: endpointParams))
builder.interceptors.add(AWSClientRuntime.UserAgentMiddleware<PutFooInput, PutFooOutput>(serviceID: serviceName, version: "1.0.0", config: config))
builder.interceptors.add(AWSClientRuntime.UserAgentMiddleware<PutFooInput, PutFooOutput>(serviceID: serviceName, config: config))
builder.selectAuthScheme(ClientRuntime.AuthSchemeMiddleware<PutFooOutput>())
var metricsAttributes = Smithy.Attributes()
metricsAttributes.set(key: ClientRuntime.OrchestratorMetricsAttributesKeys.service, value: "Example")
Expand Down Expand Up @@ -272,7 +272,7 @@ extension PutObjectInput {
let endpointParams = EndpointParams()
context.attributes.set(key: Smithy.AttributeKey<EndpointParams>(name: "EndpointParams"), value: endpointParams)
builder.applyEndpoint(AWSClientRuntime.EndpointResolverMiddleware<PutObjectOutput, EndpointParams>(endpointResolverBlock: { [config] in try config.endpointResolver.resolve(params: ${'$'}0) }, endpointParams: endpointParams))
builder.interceptors.add(AWSClientRuntime.UserAgentMiddleware<PutObjectInput, PutObjectOutput>(serviceID: serviceName, version: "1.0.0", config: config))
builder.interceptors.add(AWSClientRuntime.UserAgentMiddleware<PutObjectInput, PutObjectOutput>(serviceID: serviceName, config: config))
builder.selectAuthScheme(ClientRuntime.AuthSchemeMiddleware<PutObjectOutput>())
var metricsAttributes = Smithy.Attributes()
metricsAttributes.set(key: ClientRuntime.OrchestratorMetricsAttributesKeys.service, value: "S3")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class AWSQueryOperationStackTest {
builder.applySigner(ClientRuntime.SignerMiddleware<NoInputAndOutputOutput>())
let endpointParams = EndpointParams()
builder.applyEndpoint(AWSClientRuntime.EndpointResolverMiddleware<NoInputAndOutputOutput, EndpointParams>(endpointResolverBlock: { [config] in try config.endpointResolver.resolve(params: ${'$'}0) }, endpointParams: endpointParams))
builder.interceptors.add(AWSClientRuntime.UserAgentMiddleware<NoInputAndOutputInput, NoInputAndOutputOutput>(serviceID: serviceName, version: "1.0.0", config: config))
builder.interceptors.add(AWSClientRuntime.UserAgentMiddleware<NoInputAndOutputInput, NoInputAndOutputOutput>(serviceID: serviceName, config: config))
builder.serialize(ClientRuntime.BodyMiddleware<NoInputAndOutputInput, NoInputAndOutputOutput, SmithyFormURL.Writer>(rootNodeInfo: "", inputWritingClosure: NoInputAndOutputInput.write(value:to:)))
builder.interceptors.add(ClientRuntime.ContentTypeMiddleware<NoInputAndOutputInput, NoInputAndOutputOutput>(contentType: "application/x-www-form-urlencoded"))
builder.selectAuthScheme(ClientRuntime.AuthSchemeMiddleware<NoInputAndOutputOutput>())
Expand Down
Loading