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

feat: Add OS version info to user agent for Linux & Windows #738

Merged
merged 3 commits into from
May 24, 2024

Conversation

sichanyoo
Copy link
Contributor

@sichanyoo sichanyoo commented May 23, 2024

Issue #

awslabs/aws-sdk-swift#1206

Description of changes

Delete no-longer-necessary compiler directives.
Apple recently implemented getting OS versions for Linux & Windows for us in Foundation.ProcessInfo.

Tested on Linux via cloud desktop running Amazon Linux 2.
Example User-Agent header value from test run:

User-Agent: aws-sdk-swift/1.0 ua/2.0 api/sts#1.0 os/linux#5.10.216 lang/swift#5.9 cfg/retry-mode#legacy

Scope

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link
Contributor

@dayaffe dayaffe left a comment

Choose a reason for hiding this comment

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

Please see my comment on using ProcessInfo from swift-foundations instead of using Glibc

Comment on lines 17 to 31
#elseif os(Linux)
import Glibc
public struct PlatformOperationSystemVersion {
static public func operatingSystemVersion() -> String? {
var sysInfo = utsname()
uname(&sysInfo)
var local = sysInfo
let releaseVersion = withUnsafePointer(to: &local.release) {
$0.withMemoryRebound(to: CChar.self, capacity: MemoryLayout.size(ofValue: sysInfo.release)) {
String(cString: $0)
}
}
return releaseVersion
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

swift-foundations provides ProcessInfo have you tried that out? It looks like it has a linux implementation and perhaps even a windows implementation for obtaining operatingSystemVersion. I think we can use that directly

https://github.com/apple/swift-foundation/blob/d73d7c1370fc4e9414fce5f109f497ff75425fff/Sources/FoundationEssentials/ProcessInfo/ProcessInfo.swift#L261

}
return releaseVersion
}
}
#else
// TODO: Implement for Linux & Windows
Copy link
Contributor

Choose a reason for hiding this comment

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

We should remove the TODO

@sichanyoo sichanyoo requested a review from dayaffe May 24, 2024 18:25
@sichanyoo sichanyoo changed the title feat: Add OS version info to user agent for Linux feat: Add OS version info to user agent for Linux & Windows May 24, 2024
Copy link
Contributor

@dayaffe dayaffe left a comment

Choose a reason for hiding this comment

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

LGTM

@sichanyoo sichanyoo merged commit 129e98b into main May 24, 2024
17 checks passed
@sichanyoo sichanyoo deleted the feat/useragent-os-versions branch May 24, 2024 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants