MCPcopy Index your code
hub / github.com/coder/coder / runRemoteSSH

Function runRemoteSSH

cli/ssh.go:1231–1255  ·  view source on GitHub ↗

runRemoteSSH runs a command on a remote machine/workspace via SSH.

(sshClient *gossh.Client, stdin io.Reader, cmd string)

Source from the content-addressed store, hash-verified

1229
1230// runRemoteSSH runs a command on a remote machine/workspace via SSH.
1231func runRemoteSSH(sshClient *gossh.Client, stdin io.Reader, cmd string) ([]byte, error) {
1232 sess, err := sshClient.NewSession()
1233 if err != nil {
1234 return nil, xerrors.Errorf("create SSH session")
1235 }
1236 defer sess.Close()
1237
1238 stderr := bytes.NewBuffer(nil)
1239 sess.Stdin = stdin
1240 // On fish, this was outputting to stderr instead of stdout.
1241 // The tests pass differently on different Linux machines,
1242 // so it's best we capture the output of both.
1243 out, err := sess.CombinedOutput(cmd)
1244 if err != nil {
1245 return out, xerrors.Errorf(
1246 "`%s` failed: stderr: %s\n\nstdout: %s:\n\n%w",
1247 cmd,
1248 bytes.TrimSpace(stderr.Bytes()),
1249 bytes.TrimSpace(out),
1250 err,
1251 )
1252 }
1253
1254 return out, nil
1255}
1256
1257func uploadGPGKeys(ctx context.Context, sshClient *gossh.Client) error {
1258 // Check if the agent is running in the workspace already.

Callers 2

uploadGPGKeysFunction · 0.85
remoteGPGAgentSocketFunction · 0.85

Calls 4

NewSessionMethod · 0.80
CloseMethod · 0.65
ErrorfMethod · 0.45
BytesMethod · 0.45

Tested by

no test coverage detected