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

Function sshRun

cmd/wsh/cmd/wshcmd-ssh.go:40–110  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

38}
39
40func sshRun(cmd *cobra.Command, args []string) (rtnErr error) {
41 defer func() {
42 sendActivity("ssh", rtnErr == nil)
43 }()
44
45 sshArg := args[0]
46 var err error
47 sshArg, err = applySSHOverrides(sshArg, sshLogin, sshPort)
48 if err != nil {
49 return err
50 }
51 blockId := RpcContext.BlockId
52 if blockId == "" && !newBlock {
53 return fmt.Errorf("cannot determine blockid (not in JWT)")
54 }
55
56 // Create connection request
57 connOpts := wshrpc.ConnRequest{
58 Host: sshArg,
59 LogBlockId: blockId,
60 Keywords: wconfig.ConnKeywords{
61 SshIdentityFile: identityFiles,
62 },
63 }
64 wshclient.ConnConnectCommand(RpcClient, connOpts, &wshrpc.RpcOpts{Timeout: 60000})
65
66 if newBlock {
67 tabId := getTabIdFromEnv()
68 if tabId == "" {
69 return fmt.Errorf("no WAVETERM_TABID env var set")
70 }
71
72 // Create a new block with the SSH connection
73 createMeta := map[string]any{
74 waveobj.MetaKey_View: "term",
75 waveobj.MetaKey_Controller: "shell",
76 waveobj.MetaKey_Connection: sshArg,
77 }
78 if RpcContext.Conn != "" {
79 createMeta[waveobj.MetaKey_Connection] = RpcContext.Conn
80 }
81 createBlockData := wshrpc.CommandCreateBlockData{
82 TabId: tabId,
83 BlockDef: &waveobj.BlockDef{
84 Meta: createMeta,
85 },
86 Focused: true,
87 }
88 oref, err := wshclient.CreateBlockCommand(RpcClient, createBlockData, nil)
89 if err != nil {
90 return fmt.Errorf("creating new terminal block: %w", err)
91 }
92 WriteStdout("new terminal block created with connection to %q: %s\n", sshArg, oref)
93 return nil
94 }
95
96 // Update existing block with the new connection
97 data := wshrpc.CommandSetMetaData{

Callers

nothing calls this directly

Calls 9

ConnConnectCommandFunction · 0.92
CreateBlockCommandFunction · 0.92
MakeORefFunction · 0.92
SetMetaCommandFunction · 0.92
sendActivityFunction · 0.85
applySSHOverridesFunction · 0.85
getTabIdFromEnvFunction · 0.85
WriteStdoutFunction · 0.85
WriteStderrFunction · 0.85

Tested by

no test coverage detected