Skip to content

Commit

Permalink
update port configuration precedence to something more sensisble
Browse files Browse the repository at this point in the history
  • Loading branch information
memetb committed Oct 29, 2024
1 parent b8da8da commit 31bd40a
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions libvirt/uri/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,21 +162,26 @@ func (u *ConnectionURI) dialHost(target string, sshcfg *ssh_config.Config, depth

q := u.Query()

port := u.Port()
if port == "" {
port = defaultSSHPort
if sshcfg != nil {
configuredPort, err := sshcfg.Get(target, "Port")
if err == nil && configuredPort != "" {
port = configuredPort
log.Printf("[DEBUG] using ssh port from ssh_config: '%s'", port)
}
}
// port override order of precedence (starting with highest):
// 1. specific stanza entry in ssh_config for this target (this includes default global entries in ssh config)
// 2. port specified in connection string
// 3. defaultSSHPort
port := ""

if sshcfg != nil && (configuredPort, err := sshcfg.Get(target, "Port")); err == nil && configuredPort != "" {

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

View workflow job for this annotation

GitHub Actions / Lint (1.21.x)

syntax error: unexpected comma, expected )) (typecheck)

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

View workflow job for this annotation

GitHub Actions / Lint (1.21.x)

syntax error: unexpected comma, expected ) (typecheck)

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

View workflow job for this annotation

GitHub Actions / Lint (1.21.x)

expected ')', found ',' (typecheck)

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

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, 1.21)

syntax error: unexpected comma, expected )

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

View workflow job for this annotation

GitHub Actions / Build (macos-latest, 1.21)

syntax error: unexpected comma, expected )

port = configuredPort
log.Printf("[DEBUG] using ssh port from ssh_config: '%s'", port)

} else if u.Port() != "" {

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

View workflow job for this annotation

GitHub Actions / Lint (1.21.x)

expected '{', found 'if' (typecheck)

port = u.Port()
log.Printf("[DEBUG] using connection string port ('%s')", port)
} else {
log.Printf("[DEBUG] using ssh port from querystring: '%s'", port)

port := defaultSSHPort
log.Printf("[DEBUG] using default port for ssh connection ('%s')", port)
}
log.Printf("[DEBUG] port for ssh connection is: '%s'", port)

hostName := target
if sshcfg != nil {
Expand Down

0 comments on commit 31bd40a

Please sign in to comment.