From 4edd36a333e7c559954b900eb32e75bf54edf15e Mon Sep 17 00:00:00 2001 From: Vadym Popov Date: Fri, 25 Oct 2024 12:50:51 -0400 Subject: [PATCH] Replace ToolsMode with ToolsAutoUpdate --- api/client/webclient/webclient.go | 4 ++-- lib/autoupdate/tools/updater.go | 3 +-- lib/web/apiserver.go | 6 ++---- lib/web/apiserver_ping_test.go | 24 ++++++++++++------------ 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/api/client/webclient/webclient.go b/api/client/webclient/webclient.go index 95ae0ea9747c3..32466053b3ba8 100644 --- a/api/client/webclient/webclient.go +++ b/api/client/webclient/webclient.go @@ -334,8 +334,8 @@ type ProxySettings struct { type AutoUpdateSettings struct { // ToolsVersion defines the version of {tsh, tctl} for client auto update. ToolsVersion string `json:"tools_version"` - // ToolsMode defines mode client auto update feature `enabled|disabled`. - ToolsMode string `json:"tools_mode"` + // ToolsAutoUpdate indicates if the requesting tools client should be updated. + ToolsAutoUpdate bool `json:"tools_auto_update"` } // KubeProxySettings is kubernetes proxy settings diff --git a/lib/autoupdate/tools/updater.go b/lib/autoupdate/tools/updater.go index 8d12b2901aa2b..95112058094b7 100644 --- a/lib/autoupdate/tools/updater.go +++ b/lib/autoupdate/tools/updater.go @@ -42,7 +42,6 @@ import ( "github.com/gravitational/teleport/api/client/webclient" "github.com/gravitational/teleport/api/constants" - "github.com/gravitational/teleport/api/types/autoupdate" "github.com/gravitational/teleport/lib/utils" "github.com/gravitational/teleport/lib/utils/packaging" ) @@ -196,7 +195,7 @@ func (u *Updater) CheckRemote(ctx context.Context, proxyAddr string) (version st } switch { - case resp.AutoUpdate.ToolsMode != autoupdate.ToolsUpdateModeEnabled || resp.AutoUpdate.ToolsVersion == "": + case !resp.AutoUpdate.ToolsAutoUpdate || resp.AutoUpdate.ToolsVersion == "": return toolsVersion, true, nil case u.localVersion == resp.AutoUpdate.ToolsVersion: return resp.AutoUpdate.ToolsVersion, false, nil diff --git a/lib/web/apiserver.go b/lib/web/apiserver.go index faaffa2ff3e1e..91860c64ce7fa 100644 --- a/lib/web/apiserver.go +++ b/lib/web/apiserver.go @@ -1551,10 +1551,8 @@ func (h *Handler) find(w http.ResponseWriter, r *http.Request, p httprouter.Para // This ensures we fail open and don't accidentally update agents if something is going wrong. // If we want to enable AUs by default, it would be better to create a default "autoupdate_config" resource // than changing this logic. - if autoUpdateConfig.GetSpec().GetTools() == nil { - response.AutoUpdate.ToolsMode = autoupdate.ToolsUpdateModeDisabled - } else { - response.AutoUpdate.ToolsMode = autoUpdateConfig.GetSpec().GetTools().GetMode() + if autoUpdateConfig.GetSpec().GetTools() != nil { + response.AutoUpdate.ToolsAutoUpdate = autoUpdateConfig.GetSpec().GetTools().GetMode() == autoupdate.ToolsUpdateModeEnabled } autoUpdateVersion, err := h.cfg.AccessPoint.GetAutoUpdateVersion(r.Context()) diff --git a/lib/web/apiserver_ping_test.go b/lib/web/apiserver_ping_test.go index 903a204fe2228..6da0b530f0867 100644 --- a/lib/web/apiserver_ping_test.go +++ b/lib/web/apiserver_ping_test.go @@ -305,8 +305,8 @@ func TestPing_autoUpdateResources(t *testing.T) { { name: "resources not defined", expected: webclient.AutoUpdateSettings{ - ToolsVersion: api.Version, - ToolsMode: autoupdate.ToolsUpdateModeDisabled, + ToolsVersion: api.Version, + ToolsAutoUpdate: false, }, }, { @@ -317,8 +317,8 @@ func TestPing_autoUpdateResources(t *testing.T) { }, }, expected: webclient.AutoUpdateSettings{ - ToolsMode: autoupdate.ToolsUpdateModeEnabled, - ToolsVersion: api.Version, + ToolsAutoUpdate: true, + ToolsVersion: api.Version, }, cleanup: true, }, @@ -327,8 +327,8 @@ func TestPing_autoUpdateResources(t *testing.T) { config: &autoupdatev1pb.AutoUpdateConfigSpec{}, version: &autoupdatev1pb.AutoUpdateVersionSpec{}, expected: webclient.AutoUpdateSettings{ - ToolsVersion: api.Version, - ToolsMode: autoupdate.ToolsUpdateModeDisabled, + ToolsVersion: api.Version, + ToolsAutoUpdate: false, }, cleanup: true, }, @@ -340,8 +340,8 @@ func TestPing_autoUpdateResources(t *testing.T) { }, }, expected: webclient.AutoUpdateSettings{ - ToolsVersion: "1.2.3", - ToolsMode: autoupdate.ToolsUpdateModeDisabled, + ToolsVersion: "1.2.3", + ToolsAutoUpdate: false, }, cleanup: true, }, @@ -358,8 +358,8 @@ func TestPing_autoUpdateResources(t *testing.T) { }, }, expected: webclient.AutoUpdateSettings{ - ToolsMode: autoupdate.ToolsUpdateModeEnabled, - ToolsVersion: "1.2.3", + ToolsAutoUpdate: true, + ToolsVersion: "1.2.3", }, }, { @@ -375,8 +375,8 @@ func TestPing_autoUpdateResources(t *testing.T) { }, }, expected: webclient.AutoUpdateSettings{ - ToolsMode: autoupdate.ToolsUpdateModeDisabled, - ToolsVersion: "3.2.1", + ToolsAutoUpdate: false, + ToolsVersion: "3.2.1", }, }, }