Skip to content

Commit e786f2f

Browse files
authored
fix: [core] Hard code version number in user agent string (#98) (#533)
Add a hard coded version number to the user agent string, for an eventual identification by the Lambda service ### Motivation: It's [an issue](#108) that was open more than 5 years ago and was never addressed. At the time, the consensus was to pickup a version number for the Package.swift file and the maintainer at the time decided to wait for Swift to implement this. Five years later, and several major version of Swift later, this is still not available. I decided to move on and implement a less optimal solution. This can be replaced in the future if package version ever becomes part of Package.swift. ### Modifications: Add a version enum to isolate the versioning in one place. I decided to keep it simple and not over engineering it with major, minor, patch and pre-release. At the time, it's a simple string. This is all what we need for usage in the user agent string. ### Result: User agent now identifies as `Swift-Lambda/2,0` instead of `Swift-Lambda/unknown`
1 parent aa21cb2 commit e786f2f

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

Sources/AWSLambdaRuntime/ControlPlaneRequestEncoder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ struct ControlPlaneRequestEncoder: _EmittingChannelHandler {
9393
extension String {
9494
static let CRLF: String = "\r\n"
9595

96-
static let userAgent = "Swift-Lambda/Unknown"
96+
static let userAgent = "Swift-Lambda/\(Version.current)"
9797
static let userAgentHeader: String = "user-agent: \(userAgent)\r\n"
9898
static let unhandledErrorHeader: String = "lambda-runtime-function-error-type: Unhandled\r\n"
9999

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the SwiftAWSLambdaRuntime open source project
4+
//
5+
// Copyright (c) 2017-2018 Apple Inc. and the SwiftAWSLambdaRuntime project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of SwiftAWSLambdaRuntime project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
/// The version of the AWS Lambda Runtime.
16+
///
17+
/// This is used in the User Agent header when making requests to the AWS Lambda data Plane.
18+
///
19+
/// - Note: This is a static property that returns the current version of the AWS Lambda Runtime.
20+
/// It is used to ensure that the runtime can be identified by the AWS Lambda service.
21+
/// As such, we mainly care about major version and minor version. Patch and pre-release versions are ignored.
22+
package enum Version {
23+
/// The current version of the AWS Lambda Runtime.
24+
package static let current = "2.0"
25+
}

0 commit comments

Comments
 (0)