runRemoteSSH runs a command on a remote machine/workspace via SSH.
(sshClient *gossh.Client, stdin io.Reader, cmd string)
| 1229 | |
| 1230 | // runRemoteSSH runs a command on a remote machine/workspace via SSH. |
| 1231 | func 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 | |
| 1257 | func uploadGPGKeys(ctx context.Context, sshClient *gossh.Client) error { |
| 1258 | // Check if the agent is running in the workspace already. |
no test coverage detected