From 2c3620afd4a9a8c3ab1e45764ed4a2f9e2d9dc29 Mon Sep 17 00:00:00 2001 From: Sasha Klizhentas Date: Wed, 24 Apr 2019 12:31:43 -0700 Subject: [PATCH] Expand TELEPORT_SITE environment to tsh login, fixes #2668 The following now works: ``` TELEPORT_SITE=two.example.com tsh login ``` --- tool/tsh/tsh.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tool/tsh/tsh.go b/tool/tsh/tsh.go index cc4b59d994472..e4c9da891384a 100644 --- a/tool/tsh/tsh.go +++ b/tool/tsh/tsh.go @@ -171,6 +171,7 @@ const ( clusterEnvVar = "TELEPORT_SITE" clusterHelp = "Specify the cluster to connect" bindAddrEnvVar = "TELEPORT_LOGIN_BIND_ADDR" + authEnvVar = "TELEPORT_AUTH" ) // Run executes TSH client. same as main() but easier to test @@ -192,7 +193,7 @@ func Run(args []string, underTest bool) { app.Flag("compat", "OpenSSH compatibility flag").Hidden().StringVar(&cf.Compatibility) app.Flag("cert-format", "SSH certificate format").StringVar(&cf.CertificateFormat) app.Flag("insecure", "Do not verify server's certificate and host name. Use only in test environments").Default("false").BoolVar(&cf.InsecureSkipVerify) - app.Flag("auth", "Specify the type of authentication connector to use.").StringVar(&cf.AuthConnector) + app.Flag("auth", "Specify the type of authentication connector to use.").Envar(authEnvVar).StringVar(&cf.AuthConnector) app.Flag("namespace", "Namespace of the cluster").Default(defaults.Namespace).Hidden().StringVar(&cf.Namespace) app.Flag("gops", "Start gops endpoint on a given address").Hidden().BoolVar(&cf.Gops) app.Flag("gops-addr", "Specify gops addr to listen on").Hidden().StringVar(&cf.GopsAddr) @@ -360,6 +361,13 @@ func onLogin(cf *CLIConf) { key *client.Key ) + // populate cluster name from environment variables + // only if not set by argument (that does not support env variables) + clusterName := os.Getenv(clusterEnvVar) + if cf.SiteName == "" { + cf.SiteName = clusterName + } + if cf.IdentityFileIn != "" { utils.FatalError(trace.BadParameter("-i flag cannot be used here")) }