-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathuser_agent_test.go
53 lines (47 loc) · 1.31 KB
/
user_agent_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package awsbase
import (
"fmt"
"runtime"
"strings"
"github.com/aws/aws-sdk-go-v2/aws"
)
func awsSdkGoUserAgent() string {
// See https://github.com/aws/aws-sdk-go-v2/blob/4051ca807a0308bc9f169ca308262b328c2692a3/aws/middleware/user_agent_test.go#L18C1-L18C1
return fmt.Sprintf("%s/%s os/%s lang/go#%s md/GOOS#%s md/GOARCH#%s", aws.SDKName, aws.SDKVersion, getNormalizedOSName(), strings.TrimPrefix(runtime.Version(), "go"), runtime.GOOS, runtime.GOARCH)
}
// Copied from https://github.com/aws/aws-sdk-go-v2/blob/main/aws/middleware/osname.go
func getNormalizedOSName() (os string) {
switch runtime.GOOS {
case "android":
os = "android"
case "linux":
os = "linux"
case "windows":
os = "windows"
case "darwin":
os = "macos"
case "ios":
os = "ios"
default:
os = "other"
}
return os
}
// cleanUserAgent removes:
// * the "api/<whatever>" product that the AWS SDK adds to the user-agent string
// * the "ua/<whatever>" product that contains the User-Agent string version
func cleanUserAgent(ua string) string {
var parts []string
for _, v := range strings.Split(ua, " ") {
if strings.HasPrefix(v, "api/") {
continue
}
if strings.HasPrefix(v, "ua/") {
continue
}
parts = append(parts, v)
}
return strings.Join(parts, " ")
}