From 901cea14536f4164d81f7df1f1f250375d0d4ec7 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Wed, 12 May 2021 19:02:04 +0200 Subject: [PATCH] outposts: send build hash as part of hello Signed-off-by: Jens Langhammer --- outpost/pkg/ak/api.go | 3 +-- outpost/pkg/ak/api_ws.go | 12 +++++++----- outpost/pkg/ak/global.go | 3 +-- outpost/pkg/version.go | 13 +++++++++++++ 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/outpost/pkg/ak/api.go b/outpost/pkg/ak/api.go index c897003a4..413a8afaf 100644 --- a/outpost/pkg/ak/api.go +++ b/outpost/pkg/ak/api.go @@ -1,7 +1,6 @@ package ak import ( - "fmt" "math/rand" "net/url" "os" @@ -43,7 +42,7 @@ type APIController struct { // NewAPIController initialise new API Controller instance from URL and API token func NewAPIController(akURL url.URL, token string) *APIController { transport := httptransport.New(akURL.Host, client.DefaultBasePath, []string{akURL.Scheme}) - transport.Transport = SetUserAgent(getTLSTransport(), fmt.Sprintf("authentik-proxy@%s", pkg.VERSION)) + transport.Transport = SetUserAgent(getTLSTransport(), pkg.UserAgent()) // create the transport auth := httptransport.BearerToken(token) diff --git a/outpost/pkg/ak/api_ws.go b/outpost/pkg/ak/api_ws.go index 365c36336..898579418 100644 --- a/outpost/pkg/ak/api_ws.go +++ b/outpost/pkg/ak/api_ws.go @@ -23,7 +23,7 @@ func (ac *APIController) initWS(akURL url.URL, outpostUUID strfmt.UUID) { header := http.Header{ "Authorization": []string{authHeader}, - "User-Agent": []string{fmt.Sprintf("authentik-proxy@%s", pkg.VERSION)}, + "User-Agent": []string{pkg.UserAgent()}, } value, set := os.LookupEnv("AUTHENTIK_INSECURE") @@ -46,8 +46,9 @@ func (ac *APIController) initWS(akURL url.URL, outpostUUID strfmt.UUID) { msg := websocketMessage{ Instruction: WebsocketInstructionHello, Args: map[string]interface{}{ - "version": pkg.VERSION, - "uuid": ac.instanceUUID.String(), + "version": pkg.VERSION, + "buildHash": pkg.BUILD(), + "uuid": ac.instanceUUID.String(), }, } err := ws.WriteJSON(msg) @@ -100,8 +101,9 @@ func (ac *APIController) startWSHealth() { aliveMsg := websocketMessage{ Instruction: WebsocketInstructionHello, Args: map[string]interface{}{ - "version": pkg.VERSION, - "uuid": ac.instanceUUID.String(), + "version": pkg.VERSION, + "buildHash": pkg.BUILD(), + "uuid": ac.instanceUUID.String(), }, } err := ac.wsConn.WriteJSON(aliveMsg) diff --git a/outpost/pkg/ak/global.go b/outpost/pkg/ak/global.go index c9417dd70..b446075c5 100644 --- a/outpost/pkg/ak/global.go +++ b/outpost/pkg/ak/global.go @@ -33,8 +33,7 @@ func doGlobalSetup(config map[string]interface{}) { default: log.SetLevel(log.DebugLevel) } - buildHash := os.Getenv("GIT_BUILD_HASH") - log.WithField("buildHash", buildHash).WithField("version", pkg.VERSION).Info("Starting authentik outpost") + log.WithField("buildHash", pkg.BUILD()).WithField("version", pkg.VERSION).Info("Starting authentik outpost") var dsn string if config[ConfigErrorReportingEnabled].(bool) { diff --git a/outpost/pkg/version.go b/outpost/pkg/version.go index b68db357a..32075e595 100644 --- a/outpost/pkg/version.go +++ b/outpost/pkg/version.go @@ -1,3 +1,16 @@ package pkg +import ( + "fmt" + "os" +) + const VERSION = "2021.5.1-rc7" + +func BUILD() string { + return os.Getenv("GIT_BUILD_HASH") +} + +func UserAgent() string { + return fmt.Sprintf("authentik-outpost@%s (%s)", VERSION, BUILD()) +}