Skip to content

Commit

Permalink
chore: add version info to the user-agent
Browse files Browse the repository at this point in the history
  • Loading branch information
mozillazg committed Apr 15, 2024
1 parent 6645a9d commit 7ed696c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 4 additions & 2 deletions pkg/ramauthenticator/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ func GenerateToken(clusterId string, cred credentials.Credential) (*Token, error
ClusterId: clusterId,
Method: tea.StringValue(params.Method),
Path: tea.StringValue(req.Pathname),
Headers: map[string]string{},
Query: map[string]string{},
Headers: map[string]string{
"user-agent": version.UserAgent(),
},
Query: map[string]string{},
}
for k, v := range req.Headers {
if !signParamsWhitelist[strings.ToLower(k)] {
Expand Down
9 changes: 7 additions & 2 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"path"
"runtime"
)

var (
Expand All @@ -27,8 +28,12 @@ func BinName() string {
}

func UserAgent() string {
ua := fmt.Sprintf("%s ack-ram-tool/%s", binName, Version)
if binName == "" || binName == defaultProgramName {
return fmt.Sprintf("ack-ram-tool/%s", Version)
ua = fmt.Sprintf("ack-ram-tool/%s", Version)
}
return fmt.Sprintf("%s ack-ram-tool/%s", binName, Version)

goInfo := fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH)
ua = fmt.Sprintf("%s (%s)", ua, goInfo)
return ua
}

0 comments on commit 7ed696c

Please sign in to comment.