refactor(remote-container): remove connection method that use password

This commit is contained in:
Levi Yan
2025-04-29 18:48:01 +08:00
parent 473eab1c8c
commit 414c0ee579

View File

@@ -25,11 +25,8 @@ export default class RemoteContainer {
})
}
async firstConnect(host: string, username: string, port: number): Promise<string>; // connect with key
// deprecated
async firstConnect(host: string, username: string, port: number, password: string): Promise<string>;
async firstConnect(host: string, username: string, port: number, password?: string): Promise<string> {
// connect with key
async firstConnect(host: string, username: string, port: number): Promise<string> {
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')