From e4de00d3904b436070ac78cd49ce75037b275b8d Mon Sep 17 00:00:00 2001 From: Levi Yan Date: Tue, 13 May 2025 18:11:44 +0800 Subject: [PATCH] fix: check if private/public ssh key exists before first connect in both local and remote environment --- src/remote-container.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/remote-container.ts b/src/remote-container.ts index 40daea4..d83dcd5 100644 --- a/src/remote-container.ts +++ b/src/remote-container.ts @@ -35,16 +35,23 @@ export default class RemoteContainer { title: vscode.l10n.t("Installing vscode-server and devstar extension in container"), cancellable: false }, async (progress) => { - if (vscode.env.remoteName) { - // 远程环境 - // 检查公私钥是否存在,如果不存在,需要创建 + try { + // 无论local/remote,均需检查公私钥是否存在,如果不存在,需要创建(因为有可能在remote上创建了,但是local未创建) if (!this.user.existUserPrivateKey() || !this.user.existUserPublicKey()) { - this.user.createUserSSHKey() + await this.user.createUserSSHKey() // 上传公钥 const devstarAPIHandler = new DevstarAPIHandler() - await devstarAPIHandler.uploadUserPublicKey(this.user) + const uploadResult = await devstarAPIHandler.uploadUserPublicKey(this.user) + if (uploadResult !== "ok") { + throw new Error('Upload public key failed.') + } } + } catch (error) { + console.error("Failed to first connect container: ", error) + } + if (vscode.env.remoteName) { + // 远程环境 try { // 第一次连接 await ssh.connect({