-
Notifications
You must be signed in to change notification settings - Fork 174
Generalize User-Agent setup #3672
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
Changes from all commits
6a0e00a
f0f2073
af4e4c3
783fba4
b746f25
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package clientconn | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "runtime" | ||
| "strconv" | ||
|
|
||
| "github.com/stackrox/rox/pkg/version" | ||
| ) | ||
|
|
||
| var userAgent string | ||
|
|
||
| func init() { | ||
| SetUserAgent("stackrox") | ||
| } | ||
|
|
||
| // SetUserAgent formats and sets a value to be used in the User-Agent HTTP | ||
| // header for the requests, initiated by a process. | ||
| // Note: gorpc-go library will append the header value with its version, | ||
| // e.g. grpc-go/1.50.1. | ||
| func SetUserAgent(agent string) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a test so we can see how user agent will look like?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of relying on the processes to call This way we don't have the dependency on the consumer on making sure to have called
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| var ci string | ||
| if v, ok := os.LookupEnv("CI"); ok { | ||
| if v == "" { | ||
| ci = " CI" | ||
| } else if value, err := strconv.ParseBool(v); err == nil && value { | ||
| ci = " CI" | ||
| } | ||
| } | ||
| userAgent = fmt.Sprintf("%s/%s (%s; %s)%s", agent, version.GetMainVersion(), runtime.GOOS, runtime.GOARCH, ci) | ||
| } | ||
|
|
||
| // GetUserAgent returns the previously calculated value, which has to be set | ||
| // by the process main function via a call to SetUserAgent(). | ||
| // Default value is the one produced by SetUserAgent("stackrox"). | ||
| func GetUserAgent() string { | ||
| return userAgent | ||
| } | ||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.