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

Function setupRpcClient

cmd/wsh/cmd/wshcmd-root.go:153–179  ·  view source on GitHub ↗

returns the wrapped stdin and a new rpc client (that wraps the stdin input and stdout output)

(serverImpl wshutil.ServerImpl, jwtToken string)

Source from the content-addressed store, hash-verified

151
152// returns the wrapped stdin and a new rpc client (that wraps the stdin input and stdout output)
153func setupRpcClient(serverImpl wshutil.ServerImpl, jwtToken string) error {
154 rpcCtx, err := wshutil.ExtractUnverifiedRpcContext(jwtToken)
155 if err != nil {
156 return fmt.Errorf("error extracting rpc context from %s: %v", wshutil.WaveJwtTokenVarName, err)
157 }
158 RpcContext = *rpcCtx
159 sockName, err := wshutil.ExtractUnverifiedSocketName(jwtToken)
160 if err != nil {
161 return fmt.Errorf("error extracting socket name from %s: %v", wshutil.WaveJwtTokenVarName, err)
162 }
163 RpcClient, err = wshutil.SetupDomainSocketRpcClient(sockName, serverImpl, "wshcmd")
164 if err != nil {
165 return fmt.Errorf("error setting up domain socket rpc client: %v", err)
166 }
167 authRtn, err := wshclient.AuthenticateCommand(RpcClient, jwtToken, &wshrpc.RpcOpts{Route: wshutil.ControlRoute})
168 if err != nil {
169 return fmt.Errorf("error authenticating: %v", err)
170 }
171 RpcClientRouteId = authRtn.RouteId
172 blockId := os.Getenv("WAVETERM_BLOCKID")
173 if blockId != "" {
174 peerInfo := fmt.Sprintf("domain:block:%s", blockId)
175 wshclient.SetPeerInfoCommand(RpcClient, peerInfo, &wshrpc.RpcOpts{Route: wshutil.ControlRoute})
176 }
177 // note we don't modify WrappedStdin here (just use os.Stdin)
178 return nil
179}
180
181func isFullORef(orefStr string) bool {
182 _, err := waveobj.ParseORef(orefStr)

Callers 2

preRunSetupRpcClientFunction · 0.85
serverRunNormalFunction · 0.85

Calls 5

AuthenticateCommandFunction · 0.92
SetPeerInfoCommandFunction · 0.92

Tested by

no test coverage detected