2018-02-15 23:30:31 +00:00
|
|
|
package useragent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"runtime"
|
|
|
|
|
2019-04-12 21:54:35 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/logical"
|
|
|
|
"github.com/hashicorp/vault/sdk/version"
|
2018-02-15 23:30:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
// projectURL is the project URL.
|
|
|
|
projectURL = "https://www.vaultproject.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 Vault.
|
2018-08-06 16:02:04 +00:00
|
|
|
//
|
|
|
|
// e.g. Vault/0.10.4 (+https://www.vaultproject.io/; go1.10.1)
|
2018-02-15 23:30:31 +00:00
|
|
|
func String() string {
|
|
|
|
return fmt.Sprintf("Vault/%s (+%s; %s)",
|
|
|
|
versionFunc(), projectURL, rt)
|
|
|
|
}
|
2018-08-06 16:02:04 +00:00
|
|
|
|
|
|
|
// PluginString is usable by plugins to return a user-agent string reflecting
|
|
|
|
// the running Vault version and an optional plugin name.
|
|
|
|
//
|
|
|
|
// e.g. Vault/0.10.4 (+https://www.vaultproject.io/; azure-auth; go1.10.1)
|
|
|
|
func PluginString(env *logical.PluginEnvironment, pluginName string) string {
|
|
|
|
var name string
|
|
|
|
|
|
|
|
if pluginName != "" {
|
|
|
|
name = pluginName + "; "
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Sprintf("Vault/%s (+%s; %s%s)",
|
|
|
|
env.VaultVersion, projectURL, name, rt)
|
|
|
|
}
|