Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion integration/autoupdate/tools/updater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ func TestUpdate(t *testing.T) {

// Verify that the installed version is equal to requested one.
cmd := exec.CommandContext(ctx, tctlPath, "version")
var stderr bytes.Buffer
cmd.Stderr = &stderr
out, err := cmd.Output()
require.NoError(t, err)
require.NoError(t, err, stderr.String())

matches := pattern.FindStringSubmatch(string(out))
require.Len(t, matches, 2)
Expand Down
13 changes: 3 additions & 10 deletions tool/tctl/common/client/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ import (
libmfa "github.com/gravitational/teleport/lib/client/mfa"
"github.com/gravitational/teleport/lib/client/sso"
"github.com/gravitational/teleport/lib/reversetunnelclient"
"github.com/gravitational/teleport/lib/service/servicecfg"
"github.com/gravitational/teleport/lib/utils"
"github.com/gravitational/teleport/tool/common"
tctlcfg "github.com/gravitational/teleport/tool/tctl/common/config"
)

// InitFunc initiates connection to auth service, makes ping request and return the client instance.
Expand All @@ -47,13 +45,8 @@ import (
type InitFunc func(ctx context.Context) (client *authclient.Client, close func(context.Context), err error)

// GetInitFunc wraps lazy loading auth init function for commands which requires the auth client.
func GetInitFunc(ccf tctlcfg.GlobalCLIFlags, cfg *servicecfg.Config) InitFunc {
func GetInitFunc(clientConfig *authclient.Config) InitFunc {
return func(ctx context.Context) (*authclient.Client, func(context.Context), error) {
clientConfig, err := tctlcfg.ApplyConfig(&ccf, cfg)
if err != nil {
return nil, nil, trace.Wrap(err)
}

resolver, err := reversetunnelclient.CachingResolver(
ctx,
reversetunnelclient.WebClientResolver(&webclient.Config{
Expand All @@ -70,7 +63,7 @@ func GetInitFunc(ccf tctlcfg.GlobalCLIFlags, cfg *servicecfg.Config) InitFunc {
dialer, err := reversetunnelclient.NewTunnelAuthDialer(reversetunnelclient.TunnelAuthDialerConfig{
Resolver: resolver,
ClientConfig: clientConfig.SSH,
Log: cfg.Logger,
Log: clientConfig.Log,
InsecureSkipTLSVerify: clientConfig.Insecure,
GetClusterCAs: apiclient.ClusterCAsFromCertPool(clientConfig.TLS.RootCAs),
})
Expand All @@ -87,7 +80,7 @@ func GetInitFunc(ccf tctlcfg.GlobalCLIFlags, cfg *servicecfg.Config) InitFunc {
}
fmt.Fprintf(os.Stderr,
"ERROR: Cannot connect to the auth server. Is the auth server running on %q?\n",
cfg.AuthServerAddresses()[0].Addr)
clientConfig.AuthServers[0].Addr)
return nil, nil, trace.NewAggregate(&common.ExitCodeError{Code: 1}, err)
}

Expand Down
8 changes: 7 additions & 1 deletion tool/tctl/common/tctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,13 @@ func TryRun(ctx context.Context, commands []CLICommand, args []string) error {

cfg.Debug = ccf.Debug

clientFunc := commonclient.GetInitFunc(ccf, cfg)
clientConfig, err := tctlcfg.ApplyConfig(&ccf, cfg)
if err != nil {
return trace.Wrap(err)
}

clientFunc := commonclient.GetInitFunc(clientConfig)

// Execute whatever is selected.
for _, c := range commands {
match, err := c.TryRun(ctx, selectedCmd, clientFunc)
Expand Down
Loading