fix: check if private/public ssh key exists before first connect in both local and remote environment

This commit is contained in:
Levi Yan
2025-05-13 18:11:44 +08:00
parent 4550f20296
commit e4de00d390

View File

@@ -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({