()
| 207 | ["#cloud-config", "ssh_authorized_keys:", ` - ${publicKey}`].join("\n"); |
| 208 | |
| 209 | const freePort = (): Promise<number> => |
| 210 | new Promise((resolve, reject) => { |
| 211 | const srv = net.createServer(); |
| 212 | srv.on("error", reject); |
| 213 | srv.listen(0, "127.0.0.1", () => { |
| 214 | const port = (srv.address() as net.AddressInfo).port; |
| 215 | srv.close(() => resolve(port)); |
| 216 | }); |
| 217 | }); |
| 218 | |
| 219 | const waitLocalPort = async (port: number, attempts = 40): Promise<void> => { |
| 220 | for (let i = 0; i < attempts; i++) { |