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 // connect with key
// deprecated async firstConnect(host: string, username: string, port: number): Promise<string> {
async firstConnect(host: string, username: string, port: number, password: string): Promise<string>;
async firstConnect(host: string, username: string, port: number, password?: string): Promise<string> {
return new Promise(async (resolve) => { return new Promise(async (resolve) => {
const ssh = new NodeSSH(); const ssh = new NodeSSH();
vscode.window.withProgress({ vscode.window.withProgress({
@@ -38,21 +35,20 @@ export default class RemoteContainer {
cancellable: false cancellable: false
}, async (progress) => { }, async (progress) => {
try { try {
if (password === undefined) { // connect with key
// connect with key await ssh.connect({
await ssh.connect({ host: host,
host: host, username: username,
username: username, port: port,
port: port, privateKeyPath: this.user.getUserPrivateKeyPath()
privateKeyPath: this.user.getUserPrivateKeyPath() });
}); progress.report({ message: vscode.l10n.t("Connected! Start installation") });
progress.report({ message: vscode.l10n.t("Connected! Start installation")});
// install vscode-server and devstar extension // install vscode-server and devstar extension
const vscodeCommitId = await utils.getVsCodeCommitId() const vscodeCommitId = await utils.getVsCodeCommitId()
if ("" != vscodeCommitId) { if ("" != vscodeCommitId) {
const vscodeServerUrl = `https://vscode.download.prss.microsoft.com/dbazure/download/stable/${vscodeCommitId}/vscode-server-linux-x64.tar.gz` const vscodeServerUrl = `https://vscode.download.prss.microsoft.com/dbazure/download/stable/${vscodeCommitId}/vscode-server-linux-x64.tar.gz`
const installVscodeServerScript = ` const installVscodeServerScript = `
mkdir -p ~/.vscode-server/bin/${vscodeCommitId} && \\ mkdir -p ~/.vscode-server/bin/${vscodeCommitId} && \\
if [ "$(ls -A ~/.vscode-server/bin/${vscodeCommitId})" ]; then if [ "$(ls -A ~/.vscode-server/bin/${vscodeCommitId})" ]; then
~/.vscode-server/bin/${vscodeCommitId}/bin/code-server --install-extension mengning.devstar ~/.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 ~/.vscode-server/bin/${vscodeCommitId}/bin/code-server --install-extension mengning.devstar
fi fi
`; `;
await ssh.execCommand(installVscodeServerScript); await ssh.execCommand(installVscodeServerScript);
console.log("vscode-server and extension installed"); console.log("vscode-server and extension installed");
vscode.window.showInformationMessage(vscode.l10n.t('Installation completed!')); 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();
} }
// only connect successfully then save the host info await ssh.dispose();
await this.storeHostInfo(host, port, username) await this.storeHostInfo(host, port, username)
resolve('success') resolve('success')