From 414c0ee579992791b48e754ce5888664ba287ca2 Mon Sep 17 00:00:00 2001 From: Levi Yan Date: Tue, 29 Apr 2025 18:48:01 +0800 Subject: [PATCH] refactor(remote-container): remove connection method that use password --- src/remote-container.ts | 78 ++++++++++------------------------------- 1 file changed, 19 insertions(+), 59 deletions(-) diff --git a/src/remote-container.ts b/src/remote-container.ts index 3f65a23..19ce19b 100644 --- a/src/remote-container.ts +++ b/src/remote-container.ts @@ -25,11 +25,8 @@ export default class RemoteContainer { }) } - async firstConnect(host: string, username: string, port: number): Promise; // connect with key - // deprecated - async firstConnect(host: string, username: string, port: number, password: string): Promise; - - async firstConnect(host: string, username: string, port: number, password?: string): Promise { + // connect with key + async firstConnect(host: string, username: string, port: number): Promise { return new Promise(async (resolve) => { const ssh = new NodeSSH(); vscode.window.withProgress({ @@ -38,21 +35,20 @@ export default class RemoteContainer { cancellable: false }, async (progress) => { try { - if (password === undefined) { - // connect with key - await ssh.connect({ - host: host, - username: username, - port: port, - privateKeyPath: this.user.getUserPrivateKeyPath() - }); - progress.report({ message: vscode.l10n.t("Connected! Start installation")}); + // connect with key + await ssh.connect({ + host: host, + username: username, + port: port, + privateKeyPath: this.user.getUserPrivateKeyPath() + }); + progress.report({ message: vscode.l10n.t("Connected! Start installation") }); - // install vscode-server and devstar extension - const vscodeCommitId = await utils.getVsCodeCommitId() - if ("" != vscodeCommitId) { - const vscodeServerUrl = `https://vscode.download.prss.microsoft.com/dbazure/download/stable/${vscodeCommitId}/vscode-server-linux-x64.tar.gz` - const installVscodeServerScript = ` + // install vscode-server and devstar extension + const vscodeCommitId = await utils.getVsCodeCommitId() + if ("" != vscodeCommitId) { + const vscodeServerUrl = `https://vscode.download.prss.microsoft.com/dbazure/download/stable/${vscodeCommitId}/vscode-server-linux-x64.tar.gz` + const installVscodeServerScript = ` mkdir -p ~/.vscode-server/bin/${vscodeCommitId} && \\ if [ "$(ls -A ~/.vscode-server/bin/${vscodeCommitId})" ]; then ~/.vscode-server/bin/${vscodeCommitId}/bin/code-server --install-extension mengning.devstar @@ -65,48 +61,12 @@ export default class RemoteContainer { ~/.vscode-server/bin/${vscodeCommitId}/bin/code-server --install-extension mengning.devstar fi `; - await ssh.execCommand(installVscodeServerScript); - console.log("vscode-server and extension installed"); - vscode.window.showInformationMessage(vscode.l10n.t('Installation completed!')); - } - - await ssh.dispose(); - } else { - // connect with password (deprecate in future) - await ssh.connect({ - host: host, - username: username, - password: password, - port: port - }); - progress.report({ message: "连接成功,开始安装" }); - - // install vscode-server and devstar extension - const vscodeCommitId = await utils.getVsCodeCommitId() - if ("" != vscodeCommitId) { - const vscodeServerUrl = `https://vscode.download.prss.microsoft.com/dbazure/download/stable/${vscodeCommitId}/vscode-server-linux-x64.tar.gz` - const installVscodeServerScript = ` - mkdir -p ~/.vscode-server/bin/${vscodeCommitId} && \\ - if [ "$(ls -A ~/.vscode-server/bin/${vscodeCommitId})" ]; then - ~/.vscode-server/bin/${vscodeCommitId}/bin/code-server --install-extension mengning.devstar - else - wget ${vscodeServerUrl} -O vscode-server-linux-x64.tar.gz && \\ - mv vscode-server-linux-x64.tar.gz ~/.vscode-server/bin/${vscodeCommitId} && \\ - cd ~/.vscode-server/bin/${vscodeCommitId} && \\ - tar -xvzf vscode-server-linux-x64.tar.gz --strip-components 1 && \\ - rm vscode-server-linux-x64.tar.gz && \\ - ~/.vscode-server/bin/${vscodeCommitId}/bin/code-server --install-extension mengning.devstar - fi - `; - await ssh.execCommand(installVscodeServerScript); - console.log("vscode-server and extension installed"); - vscode.window.showInformationMessage('安装完成!'); - } - - await ssh.dispose(); + await ssh.execCommand(installVscodeServerScript); + console.log("vscode-server and extension installed"); + vscode.window.showInformationMessage(vscode.l10n.t('Installation completed!')); } - // only connect successfully then save the host info + await ssh.dispose(); await this.storeHostInfo(host, port, username) resolve('success')