Skip to content

Commit

Permalink
Merge branch 'master' into tcsc/idc-app-resources
Browse files Browse the repository at this point in the history
  • Loading branch information
tcsc authored Nov 20, 2024
2 parents d77e3f3 + c7bb93d commit f080cb0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package updater
package tools

import (
"context"
Expand All @@ -26,7 +26,6 @@ import (

"github.com/gravitational/trace"

"github.com/gravitational/teleport/lib/autoupdate/tools"
stacksignal "github.com/gravitational/teleport/lib/utils/signal"
)

Expand All @@ -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.
Expand All @@ -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.
//
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/client/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 (
Expand Down Expand Up @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions tool/tctl/common/tctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 (
Expand Down Expand Up @@ -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)
}

Expand Down
12 changes: 6 additions & 6 deletions tool/tsh/common/tsh.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
)

Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}
}
Expand All @@ -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)
}

Expand All @@ -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)
}

Expand Down Expand Up @@ -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)
}
}
Expand Down

0 comments on commit f080cb0

Please sign in to comment.