Merge branch 'develop'

This commit is contained in:
Andrew 2023-02-02 11:28:35 -06:00
commit 1d675a8c04

View File

@ -73,7 +73,7 @@ func (remoteConfig *Host) ConnectToSSHHost(log *zerolog.Logger) (*ssh.Client, er
remoteConfig.GetPrivateKeyFromConfig() remoteConfig.GetPrivateKeyFromConfig()
remoteConfig.GetHostNameWithPort() remoteConfig.GetHostNameWithPort()
remoteConfig.GetSshUserFromConfig() remoteConfig.GetSshUserFromConfig()
log.Info().Msgf("Port: %v", remoteConfig.Port)
if remoteConfig.HostName == "" { if remoteConfig.HostName == "" {
return nil, errors.New("No hostname found or specified") return nil, errors.New("No hostname found or specified")
} }
@ -175,17 +175,19 @@ func (remoteHost *Host) GetPrivateKeyFromConfig() {
remoteHost.PrivateKeyPath, _ = resolveDir(identityFile) remoteHost.PrivateKeyPath, _ = resolveDir(identityFile)
} }
// GetHostNameWithPort checks if the port from the config file is empty // GetHostNameWithPort checks if the port from the config file is 0
// If it is the port is searched in the SSH config file // If it is the port is searched in the SSH config file(s)
func (remoteHost *Host) GetHostNameWithPort() { func (remoteHost *Host) GetHostNameWithPort() {
var port string port := fmt.Sprintf("%v", remoteHost.Port)
if remoteHost.Port == 0 {
if remoteHost.HostName == "" { if remoteHost.HostName == "" {
remoteHost.HostName, _ = remoteHost.SSHConfigFile.SshConfigFile.Get(remoteHost.Host, "HostName") remoteHost.HostName, _ = remoteHost.SSHConfigFile.SshConfigFile.Get(remoteHost.Host, "HostName")
if remoteHost.HostName == "" { if remoteHost.HostName == "" {
remoteHost.HostName = remoteHost.SSHConfigFile.DefaultUserSettings.Get(remoteHost.Host, "HostName") remoteHost.HostName = remoteHost.SSHConfigFile.DefaultUserSettings.Get(remoteHost.Host, "HostName")
} }
}
// no port specifed
if port == "0" {
port, _ = remoteHost.SSHConfigFile.SshConfigFile.Get(remoteHost.Host, "Port") port, _ = remoteHost.SSHConfigFile.SshConfigFile.Get(remoteHost.Host, "Port")
if port == "" { if port == "" {
port = remoteHost.SSHConfigFile.DefaultUserSettings.Get(remoteHost.Host, "Port") port = remoteHost.SSHConfigFile.DefaultUserSettings.Get(remoteHost.Host, "Port")
@ -193,16 +195,10 @@ func (remoteHost *Host) GetHostNameWithPort() {
port = "22" port = "22"
} }
} }
println(port)
} }
if !strings.HasSuffix(remoteHost.HostName, ":"+port) {
remoteHost.HostName = remoteHost.HostName + ":" + port remoteHost.HostName = remoteHost.HostName + ":" + port
} else {
if remoteHost.HostName == "" {
remoteHost.HostName, _ = remoteHost.SSHConfigFile.SshConfigFile.Get(remoteHost.Host, "HostName")
if remoteHost.HostName == "" {
remoteHost.HostName = remoteHost.SSHConfigFile.DefaultUserSettings.Get(remoteHost.Host, "HostName")
}
}
remoteHost.HostName = remoteHost.HostName + ":" + fmt.Sprintf("%v", remoteHost.Port)
} }
} }