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 2fbefc0
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions libvirt/uri/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,19 +162,20 @@ 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 := defaultSSHPort
if u.Port() != "" {
port = u.Port()
}
if sshcfg != nil {
configuredPort, err := sshcfg.Get(target, "Port")
if err == nil && configuredPort != "" {
log.Printf("[DEBUG] using ssh port from ssh_config: '%s'", configuredPort)
port = configuredPort
}

} else {
log.Printf("[DEBUG] using ssh port from querystring: '%s'", port)
}
log.Printf("[DEBUG] port for ssh connection is: '%s'", port)

Expand Down

0 comments on commit 2fbefc0

Please sign in to comment.