stripe-cli icon indicating copy to clipboard operation
stripe-cli copied to clipboard

feat(useragent): add Windows support for getUname() to get User-Agent.

Open Thedarkmatter10 opened this issue 6 months ago • 1 comments
trafficstars

// TODO: if there is appetite for it in the community // add support for Windows GetSystemInfo

I do have appetite for this! I’d be happy to extend the implementation to include GetSystemInfo or any additional support from the community as it becomes available or necessary.

Feature: Add Windows Support for getUname() in User Agent, similar to the existing Unix support.

This PR adds a Windows-specific implementation of the getUname() function to match the format and style used on Unix systems. It is designed to support consistent system identification for tools like Stripe CLI or other cross-platform utilities.


Summary

  • Implements getUname() for Windows systems.
  • Output matches Unix format:

Example:

OUTPUT "Windows DESKTOP-EGCRO4R 10.0.19045 Build 19045 x86_64

🔧 Technical Details

✅ Uses from x/sys/windows

  • windows.GetComputerName – gets the local hostname.
  • windows.UTF16ToString – converts UTF-16 output.

❗ Manually defined (not in x/sys/windows)

  • RtlGetVersion – for accurate OS version info (from ntdll.dll).
  • SYSTEM_INFO struct – to get CPU architecture via GetNativeSystemInfo.
  • Architecture constants like PROCESSOR_ARCHITECTURE_AMD64, ARM64, etc.

🧱 Reason for Manual Definitions

These Windows APIs/structs are currently not exposed by x/sys/windows as of 2025. This PR safely and clearly defines them using proper alignment and system docs.


🔒 Safety Notes

  • RtlGetVersion is the officially recommended way (by Microsoft) to get OS version, unlike GetVersionEx or syscall.GetVersion() which are deprecated or inaccurate post-Windows 8.1.
  • All manual structs align with Microsoft’s API layout (see sysinfoapi.h, winnt.h).

✅ Unit Test Included


TEST RESULT PHOTOS

I am using this on a Windows machine. Please find the attached photo for reference.

  1. System PROOF what i am using.

proof1

  1. Test result after executing the code :

testResult1

Thedarkmatter10 avatar Apr 29 '25 13:04 Thedarkmatter10

CLA assistant check
All committers have signed the CLA.

cla-assistant[bot] avatar Apr 29 '25 13:04 cla-assistant[bot]