From f5d2d4c5a43a58174a78e1c3e2d1e04f9804b2ee Mon Sep 17 00:00:00 2001 From: sawka Date: Tue, 3 Sep 2024 11:47:54 -0700 Subject: [PATCH] working on wsh ssh --- cmd/wsh/cmd/wshcmd-ssh.go | 44 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 cmd/wsh/cmd/wshcmd-ssh.go diff --git a/cmd/wsh/cmd/wshcmd-ssh.go b/cmd/wsh/cmd/wshcmd-ssh.go new file mode 100644 index 000000000..4a60e5e05 --- /dev/null +++ b/cmd/wsh/cmd/wshcmd-ssh.go @@ -0,0 +1,44 @@ +// Copyright 2024, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +package cmd + +import ( + "github.com/spf13/cobra" + "github.com/wavetermdev/thenextwave/pkg/waveobj" + "github.com/wavetermdev/thenextwave/pkg/wshrpc" + "github.com/wavetermdev/thenextwave/pkg/wshrpc/wshclient" +) + +var sshCmd = &cobra.Command{ + Use: "ssh", + Short: "connect this terminal to a remote host", + Args: cobra.ExactArgs(1), + Run: sshRun, + PreRunE: preRunSetupRpcClient, +} + +func init() { + rootCmd.AddCommand(sshCmd) +} + +func sshRun(cmd *cobra.Command, args []string) { + sshArg := args[0] + blockId := RpcContext.BlockId + if blockId == "" { + WriteStderr("[error] cannot determine blockid (not in JWT)\n") + return + } + data := wshrpc.CommandSetMetaData{ + ORef: waveobj.MakeORef(waveobj.OType_Block, blockId), + Meta: map[string]any{ + waveobj.MetaKey_Connection: sshArg, + }, + } + err := wshclient.SetMetaCommand(RpcClient, data, nil) + if err != nil { + WriteStderr("[error] setting switching connection: %v\n", err) + return + } + WriteStderr("switched connection to %q\n", sshArg) +}