MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / tryEnableWsh

Method tryEnableWsh

pkg/remote/conncontroller/conncontroller.go:868–920  ·  view source on GitHub ↗

returns (wsh-enabled, clientVersion, text-reason, wshError)

(ctx context.Context, clientDisplayName string)

Source from the content-addressed store, hash-verified

866
867// returns (wsh-enabled, clientVersion, text-reason, wshError)
868func (conn *SSHConn) tryEnableWsh(ctx context.Context, clientDisplayName string) WshCheckResult {
869 conn.Infof(ctx, "running tryEnableWsh...\n")
870 enableWsh, askBeforeInstall := conn.getConnWshSettings()
871 conn.Infof(ctx, "wsh settings enable:%v ask:%v\n", enableWsh, askBeforeInstall)
872 if !enableWsh {
873 return WshCheckResult{NoWshReason: "conn:wshenabled set to false", NoWshCode: NoWshCode_Disabled}
874 }
875 if askBeforeInstall {
876 allowInstall, err := conn.getPermissionToInstallWsh(ctx, clientDisplayName)
877 if err != nil {
878 log.Printf("error getting permission to install wsh: %v\n", err)
879 return WshCheckResult{NoWshReason: "error getting user permission to install", NoWshCode: NoWshCode_PermissionError, WshError: err}
880 }
881 if !allowInstall {
882 return WshCheckResult{NoWshReason: "user selected not to install wsh extensions", NoWshCode: NoWshCode_UserDeclined}
883 }
884 }
885 err := conn.OpenDomainSocketListener(ctx)
886 if err != nil {
887 conn.Infof(ctx, "ERROR opening domain socket listener: %v\n", err)
888 err = fmt.Errorf("error opening domain socket listener: %w", err)
889 return WshCheckResult{NoWshReason: "error opening domain socket", NoWshCode: NoWshCode_DomainSocketError, WshError: err}
890 }
891 needsInstall, clientVersion, osArchStr, err := conn.StartConnServer(ctx, false, true)
892 if err != nil {
893 conn.Infof(ctx, "ERROR starting conn server: %v\n", err)
894 err = fmt.Errorf("error starting conn server: %w", err)
895 return WshCheckResult{NoWshReason: "error starting connserver", NoWshCode: NoWshCode_ConnServerStartError, WshError: err}
896 }
897 if needsInstall {
898 conn.Infof(ctx, "connserver needs to be (re)installed\n")
899 err = conn.InstallWsh(ctx, osArchStr)
900 if err != nil {
901 conn.Infof(ctx, "ERROR installing wsh: %v\n", err)
902 err = fmt.Errorf("error installing wsh: %w", err)
903 return WshCheckResult{NoWshReason: "error installing wsh/connserver", NoWshCode: NoWshCode_InstallError, WshError: err}
904 }
905 needsInstall, clientVersion, _, err = conn.StartConnServer(ctx, true, true)
906 if err != nil {
907 conn.Infof(ctx, "ERROR starting conn server (after install): %v\n", err)
908 err = fmt.Errorf("error starting conn server (after install): %w", err)
909 return WshCheckResult{NoWshReason: "error starting connserver", NoWshCode: NoWshCode_PostInstallStartError, WshError: err}
910 }
911 if needsInstall {
912 conn.Infof(ctx, "conn server not installed correctly (after install)\n")
913 err = fmt.Errorf("conn server not installed correctly (after install)")
914 return WshCheckResult{NoWshReason: "connserver not installed properly", NoWshCode: NoWshCode_InstallVerifyError, WshError: err}
915 }
916 return WshCheckResult{WshEnabled: true, ClientVersion: clientVersion}
917 } else {
918 return WshCheckResult{WshEnabled: true, ClientVersion: clientVersion}
919 }
920}
921
922func (conn *SSHConn) getConnectionConfig() (wconfig.ConnKeywords, bool) {
923 config := wconfig.GetWatcher().GetFullConfig()

Callers 1

connectInternalMethod · 0.95

Calls 6

InfofMethod · 0.95
getConnWshSettingsMethod · 0.95
StartConnServerMethod · 0.95
InstallWshMethod · 0.95

Tested by

no test coverage detected