diff --git a/pkg/util/useragent_roundtripper.go b/pkg/util/useragent_roundtripper.go index f062e3548..96c96199f 100644 --- a/pkg/util/useragent_roundtripper.go +++ b/pkg/util/useragent_roundtripper.go @@ -4,19 +4,19 @@ import ( "net/http" ) +// CertManagerUserAgent is the user agent that http clients in this codebase should use +var CertManagerUserAgent = "jetstack-cert-manager/" + version() + // UserAgentRoundTripper implements the http.RoundTripper interface and adds a User-Agent // header. type userAgentRoundTripper struct { inner http.RoundTripper } -// CertManagerUserAgent is the user agent that http clients in this codebase should use -const CertManagerUserAgent = "jetstack-cert-manager/" + AppVersion - // UserAgentRoundTripper returns a RoundTripper that functions identically to // the provided 'inner' round tripper, other than also setting a user agent. func UserAgentRoundTripper(inner http.RoundTripper) http.RoundTripper { - return UserAgentRoundTripper{ + return userAgentRoundTripper{ inner: inner, } } diff --git a/pkg/util/version.go b/pkg/util/version.go index 3ab75874b..c516efc06 100644 --- a/pkg/util/version.go +++ b/pkg/util/version.go @@ -1,7 +1,20 @@ package util +import "fmt" + var ( AppGitState = "" AppGitCommit = "" AppVersion = "canary" ) + +func version() string { + v := AppVersion + if AppGitCommit != "" { + v += "-" + AppGitCommit + } + if AppGitState != "" { + v += fmt.Sprintf(" (%v)", AppGitState) + } + return v +}