83450c8762
* vault: configure user agent on Nomad vault clients This PR attempts to set the User-Agent header on each Vault API client created by Nomad. Still need to figure a way to set User-Agent on the Vault client created internally by consul-template. * vault: fixup find-and-replace gone awry
43 lines
1,001 B
Go
43 lines
1,001 B
Go
package useragent
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"runtime"
|
|
|
|
"github.com/hashicorp/nomad/version"
|
|
)
|
|
|
|
var (
|
|
// projectURL is the project URL.
|
|
projectURL = "https://www.nomadproject.io/"
|
|
|
|
// rt is the runtime - variable for tests.
|
|
rt = runtime.Version()
|
|
|
|
// versionFunc is the func that returns the current version. This is a
|
|
// function to take into account the different build processes and distinguish
|
|
// between enterprise and oss builds.
|
|
versionFunc = func() string {
|
|
return version.GetVersion().VersionNumber()
|
|
}
|
|
)
|
|
|
|
// String returns the consistent user-agent string for Nomad.
|
|
func String() string {
|
|
return fmt.Sprintf("Nomad/%s (+%s; %s)",
|
|
versionFunc(), projectURL, rt)
|
|
}
|
|
|
|
// HeaderSetter is anything that implements SetHeaders(http.Header).
|
|
type HeaderSetter interface {
|
|
SetHeaders(http.Header)
|
|
}
|
|
|
|
// SetHeaders configures the User-Agent http.Header for the client.
|
|
func SetHeaders(client HeaderSetter) {
|
|
client.SetHeaders(http.Header{
|
|
"User-Agent": []string{String()},
|
|
})
|
|
}
|