(vmId: string, prKey: string)
| 88 | } |
| 89 | |
| 90 | async function setupSSHConfig(vmId: string, prKey: string) { |
| 91 | const devboxBinary = await which('devbox', { nothrow: true }); |
| 92 | let devboxPath = 'devbox'; |
| 93 | if (devboxBinary === null) { |
| 94 | devboxPath = await setupDevboxLauncher(); |
| 95 | } |
| 96 | // For testing change devbox to path to a compiled devbox binary or add --config |
| 97 | exec(`${devboxPath} generate ssh-config`, (error, stdout, stderr) => { |
| 98 | if (error) { |
| 99 | window.showErrorMessage('Failed to setup ssh config. Run VSCode in debug mode to see logs.'); |
| 100 | console.error(`Failed to setup ssh config: ${error}`); |
| 101 | return; |
| 102 | } |
| 103 | console.debug(`stdout: ${stdout}`); |
| 104 | console.debug(`stderr: ${stderr}`); |
| 105 | }); |
| 106 | |
| 107 | // save private key to file |
| 108 | const prkeyDir = `${process.env['HOME']}/.config/devbox/ssh/keys`; |
| 109 | await ensureDir(prkeyDir); |
| 110 | const prkeyPath = `${prkeyDir}/${vmId}.vm.devbox-vms.internal`; |
| 111 | try { |
| 112 | const prKeydata = new Uint8Array(Buffer.from(prKey)); |
| 113 | const fileHandler = await open(prkeyPath, 'w'); |
| 114 | await writeFile(fileHandler, prKeydata, { flag: 'w' }); |
| 115 | await chmod(prkeyPath, 0o600); |
| 116 | await fileHandler.close(); |
| 117 | } catch (err: any) { |
| 118 | // When a request is aborted - err is an AbortError |
| 119 | console.error('Failed to setup ssh config: ' + err); |
| 120 | throw (err); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | function connectToRemote(username: string, vmId: string, workDir: string) { |
| 125 | try { |
no test coverage detected