MCPcopy
hub / github.com/wavetermdev/waveterm / findSshConfigKeywords

Function findSshConfigKeywords

pkg/remote/sshclient.go:964–1109  ·  view source on GitHub ↗

note that a `var == "yes"` will default to false but `var != "no"` will default to true when given unexpected strings

(hostPattern string)

Source from the content-addressed store, hash-verified

962// but `var != "no"` will default to true
963// when given unexpected strings
964func findSshConfigKeywords(hostPattern string) (connKeywords *wconfig.ConnKeywords, outErr error) {
965 defer func() {
966 panicErr := panichandler.PanicHandler("sshclient:find-ssh-config-keywords", recover())
967 if panicErr != nil {
968 outErr = panicErr
969 }
970 }()
971 WaveSshConfigUserSettings().ReloadConfigs()
972 sshKeywords := &wconfig.ConnKeywords{}
973 var err error
974
975 userRaw, err := WaveSshConfigUserSettings().GetStrict(hostPattern, "User")
976 if err != nil {
977 return nil, err
978 }
979 userClean := trimquotes.TryTrimQuotes(userRaw)
980 if userClean == "" {
981 userDetails, err := user.Current()
982 if err != nil {
983 return nil, err
984 }
985 userClean = userDetails.Username
986 }
987 sshKeywords.SshUser = &userClean
988
989 hostNameRaw, err := WaveSshConfigUserSettings().GetStrict(hostPattern, "HostName")
990 if err != nil {
991 return nil, err
992 }
993 // manually implementing default HostName here as it is not handled by ssh_config library
994 hostNameProcessed := trimquotes.TryTrimQuotes(hostNameRaw)
995 if hostNameProcessed == "" {
996 sshKeywords.SshHostName = &hostPattern
997 } else {
998 sshKeywords.SshHostName = &hostNameRaw
999 }
1000
1001 portRaw, err := WaveSshConfigUserSettings().GetStrict(hostPattern, "Port")
1002 if err != nil {
1003 return nil, err
1004 }
1005 sshKeywords.SshPort = utilfn.Ptr(trimquotes.TryTrimQuotes(portRaw))
1006
1007 identityFileRaw := WaveSshConfigUserSettings().GetAll(hostPattern, "IdentityFile")
1008 for i := 0; i < len(identityFileRaw); i++ {
1009 identityFileRaw[i] = trimquotes.TryTrimQuotes(identityFileRaw[i])
1010 }
1011 sshKeywords.SshIdentityFile = identityFileRaw
1012
1013 batchModeRaw, err := WaveSshConfigUserSettings().GetStrict(hostPattern, "BatchMode")
1014 if err != nil {
1015 return nil, err
1016 }
1017 sshKeywords.SshBatchMode = utilfn.Ptr(strings.ToLower(trimquotes.TryTrimQuotes(batchModeRaw)) == "yes")
1018
1019 // we currently do not support host-bound or unbound but will use yes when they are selected
1020 pubkeyAuthenticationRaw, err := WaveSshConfigUserSettings().GetStrict(hostPattern, "PubkeyAuthentication")
1021 if err != nil {

Callers 1

ConnectToClientFunction · 0.85

Calls 7

PanicHandlerFunction · 0.92
TryTrimQuotesFunction · 0.92
PtrFunction · 0.92
DetectLocalShellPathFunction · 0.92
ExpandHomeDirFunction · 0.92
OutputMethod · 0.80

Tested by

no test coverage detected