From 2f050c069751599a566d1f6c98f5ef849022dc93 Mon Sep 17 00:00:00 2001 From: Stefan Majer Date: Thu, 3 Sep 2026 13:38:30 +0200 Subject: [PATCH] Adopt machine console to new metal-console --- cmd/firewall.go | 2 +- cmd/machine.go | 2 +- cmd/ssh.go | 34 ++++++++++++++++------------------ 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/cmd/firewall.go b/cmd/firewall.go index f4759fd..a9ae97e 100644 --- a/cmd/firewall.go +++ b/cmd/firewall.go @@ -296,7 +296,7 @@ func (c *firewallCmd) firewallPureSSH(fwAllocation *models.V1MachineAllocation) } for _, ip := range nw.Ips { if portOpen(ip, "22", time.Second) { - err = sshClient("metal", viper.GetString("identity"), ip, 22, nil, false) + err = sshClient("metal", viper.GetString("identity"), ip, 22, nil) if err != nil { return err } diff --git a/cmd/machine.go b/cmd/machine.go index f070a10..c870cbc 100644 --- a/cmd/machine.go +++ b/cmd/machine.go @@ -1306,7 +1306,7 @@ func (c *machineCmd) machineConsole(args []string) error { token = authContext.IDToken } - err = sshClient(id, viper.GetString("sshidentity"), parsedurl.Host, bmcConsolePort, &token, viper.GetBool("admin")) + err = sshClient(id, viper.GetString("sshidentity"), parsedurl.Host, bmcConsolePort, &token) if err != nil { return fmt.Errorf("machine console error:%w", err) } diff --git a/cmd/ssh.go b/cmd/ssh.go index 0c182fe..de2f02b 100644 --- a/cmd/ssh.go +++ b/cmd/ssh.go @@ -59,35 +59,33 @@ func (c *firewallCmd) firewallSSHViaVPN(firewall *models.V1FirewallResponse) (er } // sshClient opens an interactive ssh session to the host on port with user, authenticated by the key. -func sshClient(user, keyfile, host string, port int, idToken *string, passwordAuth bool) error { +func sshClient(user, keyfile, host string, port int, idToken *string) error { var opts []metalssh.ConnectOpt - if passwordAuth { - opts = append(opts, metalssh.ConnectOptOutputPassword(*idToken)) - } else { - if keyfile == "" { - var err error - keyfile, err = searchSSHKey() - if err != nil { - return err - } - } - - privateKey, err := os.ReadFile(keyfile) + if keyfile == "" { + var err error + keyfile, err = searchSSHKey() if err != nil { return err } + } - opts = append(opts, metalssh.ConnectOptOutputPrivateKey(privateKey)) + privateKey, err := os.ReadFile(keyfile) + if err != nil { + return err } + opts = append(opts, metalssh.ConnectOptOutputPrivateKey(privateKey)) + s, err := metalssh.NewClient(user, host, port, opts...) if err != nil { return err } - var env *metalssh.Env - if idToken != nil { - env = &metalssh.Env{"LC_METAL_STACK_OIDC_TOKEN": *idToken} + + env := map[string]string{ + "LC_METAL_STACK_OIDC_TOKEN": pointer.SafeDeref(idToken), } - return s.Connect(env) + sshEnv := metalssh.Env(env) + + return s.Connect(&sshEnv) }