diff --git a/tool/common/updater/client_tools.go b/lib/autoupdate/tools/helper.go similarity index 91% rename from tool/common/updater/client_tools.go rename to lib/autoupdate/tools/helper.go index 6949664b35b7d..79069c3d3c90b 100644 --- a/tool/common/updater/client_tools.go +++ b/lib/autoupdate/tools/helper.go @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package updater +package tools import ( "context" @@ -26,7 +26,6 @@ import ( "github.com/gravitational/trace" - "github.com/gravitational/teleport/lib/autoupdate/tools" stacksignal "github.com/gravitational/teleport/lib/utils/signal" ) @@ -38,12 +37,12 @@ import ( // If $TELEPORT_HOME/bin contains downloaded client tools, it always re-executes // using the version from the home directory. func CheckAndUpdateLocal(ctx context.Context, currentVersion string) error { - toolsDir, err := tools.Dir() + toolsDir, err := Dir() if err != nil { slog.WarnContext(ctx, "Client tools update is disabled", "error", err) return nil } - updater := tools.NewUpdater(toolsDir, currentVersion) + updater := NewUpdater(toolsDir, currentVersion) // At process startup, check if a version has already been downloaded to // $TELEPORT_HOME/bin or if the user has set the TELEPORT_TOOLS_VERSION // environment variable. If so, re-exec that version of client tools. @@ -66,12 +65,12 @@ func CheckAndUpdateLocal(ctx context.Context, currentVersion string) error { // If $TELEPORT_HOME/bin contains downloaded client tools, it always re-executes // using the version from the home directory. func CheckAndUpdateRemote(ctx context.Context, currentVersion string, proxy string, insecure bool) error { - toolsDir, err := tools.Dir() + toolsDir, err := Dir() if err != nil { slog.WarnContext(ctx, "Client tools update is disabled", "error", err) return nil } - updater := tools.NewUpdater(toolsDir, currentVersion) + updater := NewUpdater(toolsDir, currentVersion) // The user has typed a command like `tsh ssh ...` without being logged in, // if the running binary needs to be updated, update and re-exec. // @@ -88,7 +87,7 @@ func CheckAndUpdateRemote(ctx context.Context, currentVersion string, proxy stri return nil } -func updateAndReExec(ctx context.Context, updater *tools.Updater, toolsVersion string) error { +func updateAndReExec(ctx context.Context, updater *Updater, toolsVersion string) error { ctxUpdate, cancel := stacksignal.GetSignalHandler().NotifyContext(ctx) defer cancel() // Download the version of client tools required by the cluster. This diff --git a/lib/client/api.go b/lib/client/api.go index 5496769c47115..c74cbd81d3006 100644 --- a/lib/client/api.go +++ b/lib/client/api.go @@ -74,6 +74,7 @@ import ( "github.com/gravitational/teleport/lib/auth/touchid" wancli "github.com/gravitational/teleport/lib/auth/webauthncli" "github.com/gravitational/teleport/lib/authz" + "github.com/gravitational/teleport/lib/autoupdate/tools" libmfa "github.com/gravitational/teleport/lib/client/mfa" "github.com/gravitational/teleport/lib/client/sso" "github.com/gravitational/teleport/lib/client/terminal" @@ -95,7 +96,6 @@ import ( "github.com/gravitational/teleport/lib/utils" "github.com/gravitational/teleport/lib/utils/agentconn" logutils "github.com/gravitational/teleport/lib/utils/log" - "github.com/gravitational/teleport/tool/common/updater" ) const ( @@ -709,7 +709,7 @@ func RetryWithRelogin(ctx context.Context, tc *TeleportClient, fn func() error, return trace.Wrap(err) } - if err := updater.CheckAndUpdateRemote(ctx, teleport.Version, tc.WebProxyAddr, tc.InsecureSkipVerify); err != nil { + if err := tools.CheckAndUpdateRemote(ctx, teleport.Version, tc.WebProxyAddr, tc.InsecureSkipVerify); err != nil { return trace.Wrap(err) } diff --git a/tool/tctl/common/tctl.go b/tool/tctl/common/tctl.go index fa987c6031ea3..14f954ce91f4a 100644 --- a/tool/tctl/common/tctl.go +++ b/tool/tctl/common/tctl.go @@ -44,6 +44,7 @@ import ( "github.com/gravitational/teleport/lib/auth/authclient" "github.com/gravitational/teleport/lib/auth/state" "github.com/gravitational/teleport/lib/auth/storage" + "github.com/gravitational/teleport/lib/autoupdate/tools" "github.com/gravitational/teleport/lib/client" "github.com/gravitational/teleport/lib/client/identityfile" libmfa "github.com/gravitational/teleport/lib/client/mfa" @@ -56,7 +57,6 @@ import ( "github.com/gravitational/teleport/lib/utils" "github.com/gravitational/teleport/lib/utils/hostid" "github.com/gravitational/teleport/tool/common" - "github.com/gravitational/teleport/tool/common/updater" ) const ( @@ -107,7 +107,7 @@ type CLICommand interface { // // distribution: name of the Teleport distribution func Run(ctx context.Context, commands []CLICommand) { - if err := updater.CheckAndUpdateLocal(ctx, teleport.Version); err != nil { + if err := tools.CheckAndUpdateLocal(ctx, teleport.Version); err != nil { utils.FatalError(err) } diff --git a/tool/tsh/common/tsh.go b/tool/tsh/common/tsh.go index ac3c0a5f7a779..f2d61ef9b175f 100644 --- a/tool/tsh/common/tsh.go +++ b/tool/tsh/common/tsh.go @@ -73,6 +73,7 @@ import ( "github.com/gravitational/teleport/lib/asciitable" "github.com/gravitational/teleport/lib/auth/authclient" wancli "github.com/gravitational/teleport/lib/auth/webauthncli" + "github.com/gravitational/teleport/lib/autoupdate/tools" "github.com/gravitational/teleport/lib/benchmark" benchmarkdb "github.com/gravitational/teleport/lib/benchmark/db" "github.com/gravitational/teleport/lib/client" @@ -97,7 +98,6 @@ import ( "github.com/gravitational/teleport/tool/common" "github.com/gravitational/teleport/tool/common/fido2" "github.com/gravitational/teleport/tool/common/touchid" - "github.com/gravitational/teleport/tool/common/updater" "github.com/gravitational/teleport/tool/common/webauthnwin" ) @@ -708,7 +708,7 @@ func initLogger(cf *CLIConf) { // // DO NOT RUN TESTS that call Run() in parallel (unless you taken precautions). func Run(ctx context.Context, args []string, opts ...CliOption) error { - if err := updater.CheckAndUpdateLocal(ctx, teleport.Version); err != nil { + if err := tools.CheckAndUpdateLocal(ctx, teleport.Version); err != nil { return trace.Wrap(err) } @@ -1874,7 +1874,7 @@ func onLogin(cf *CLIConf) error { // The user is not logged in and has typed in `tsh --proxy=... login`, if // the running binary needs to be updated, update and re-exec. if profile == nil { - if err := updater.CheckAndUpdateRemote(cf.Context, teleport.Version, tc.WebProxyAddr, tc.InsecureSkipVerify); err != nil { + if err := tools.CheckAndUpdateRemote(cf.Context, teleport.Version, tc.WebProxyAddr, tc.InsecureSkipVerify); err != nil { return trace.Wrap(err) } } @@ -1892,7 +1892,7 @@ func onLogin(cf *CLIConf) error { // The user has typed `tsh login`, if the running binary needs to // be updated, update and re-exec. - if err := updater.CheckAndUpdateRemote(cf.Context, teleport.Version, tc.WebProxyAddr, tc.InsecureSkipVerify); err != nil { + if err := tools.CheckAndUpdateRemote(cf.Context, teleport.Version, tc.WebProxyAddr, tc.InsecureSkipVerify); err != nil { return trace.Wrap(err) } @@ -1912,7 +1912,7 @@ func onLogin(cf *CLIConf) error { // The user has typed `tsh login`, if the running binary needs to // be updated, update and re-exec. - if err := updater.CheckAndUpdateRemote(cf.Context, teleport.Version, tc.WebProxyAddr, tc.InsecureSkipVerify); err != nil { + if err := tools.CheckAndUpdateRemote(cf.Context, teleport.Version, tc.WebProxyAddr, tc.InsecureSkipVerify); err != nil { return trace.Wrap(err) } @@ -1988,7 +1988,7 @@ func onLogin(cf *CLIConf) error { default: // The user is logged in and has typed in `tsh --proxy=... login`, if // the running binary needs to be updated, update and re-exec. - if err := updater.CheckAndUpdateRemote(cf.Context, teleport.Version, tc.WebProxyAddr, tc.InsecureSkipVerify); err != nil { + if err := tools.CheckAndUpdateRemote(cf.Context, teleport.Version, tc.WebProxyAddr, tc.InsecureSkipVerify); err != nil { return trace.Wrap(err) } }