Skip to content

Commit

Permalink
update user config to allow for nil sshcfg while also simplifying
Browse files Browse the repository at this point in the history
the code would previously get the current user (current execution's context)
whereas the cfg.User value already takes the ConnectionURI's set username which
should be sufficient as a default value check.
  • Loading branch information
memetb committed Oct 13, 2024
1 parent 2ef9c6a commit 2e7900a
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions libvirt/uri/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"log"
"net"
"os"
"os/user"
"path/filepath"
"strings"

Expand Down Expand Up @@ -275,20 +274,16 @@ func (u *ConnectionURI) dialHost(target string, sshcfg *ssh_config.Config, depth
}
}

if cfg.User == "" {
// cfg.User value defaults to u.User.Username()
if sshcfg != nil {
sshu, err := sshcfg.Get(target, "User")
log.Printf("[DEBUG] SSH User for target '%v' is '%v'", target, sshu)
if err != nil {
log.Printf("[DEBUG] ssh user: using current login")
u, err := user.Current()
if err != nil {
return nil, fmt.Errorf("unable to get username: %w", err)
}
sshu = u.Username
log.Printf("[DEBUG] ssh user for target '%v' is overriden to '%v'", target, sshu)

Check failure on line 281 in libvirt/uri/ssh.go

View workflow job for this annotation

GitHub Actions / Lint (1.21.x)

`overriden` is a misspelling of `overridden` (misspell)
cfg.User = sshu
}
cfg.User = sshu
}


cfg.Auth = u.parseAuthMethods(target, sshcfg)
if len(cfg.Auth) < 1 {
return nil, fmt.Errorf("could not configure SSH authentication methods")
Expand Down

0 comments on commit 2e7900a

Please sign in to comment.