refactor: open remote folder also need username, port now and change the naming format of host in config
This commit is contained in:
@@ -55,19 +55,18 @@ export default class DSHome {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'firstOpenRemoteFolder':
|
case 'firstOpenRemoteFolder':
|
||||||
const path = data.path
|
|
||||||
await this.remoteContainer.firstConnect(data.host, data.username, data.port)
|
await this.remoteContainer.firstConnect(data.host, data.username, data.port)
|
||||||
.then((_res) => {
|
.then((_res) => {
|
||||||
if (_res == 'success') {
|
if (_res == 'success') {
|
||||||
// only success then open folder
|
// only success then open folder
|
||||||
this.remoteContainer.openRemoteFolder(data.host, path);
|
this.remoteContainer.openRemoteFolder(data.host, data.username, data.port, data.path);
|
||||||
}
|
}
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
console.error(`Failed to connect ${data.host}: `, error)
|
console.error(`Failed to connect ${data.host}: `, error)
|
||||||
})
|
})
|
||||||
break;
|
break;
|
||||||
case 'openRemoteFolder':
|
case 'openRemoteFolder':
|
||||||
this.remoteContainer.openRemoteFolder(data.host, data.path);
|
this.remoteContainer.openRemoteFolder(data.host, data.username, data.port, data.path);
|
||||||
break;
|
break;
|
||||||
// ----------------- not frequent -----------------------
|
// ----------------- not frequent -----------------------
|
||||||
case 'setUserToken':
|
case 'setUserToken':
|
||||||
|
@@ -128,9 +128,10 @@ export default class RemoteContainer {
|
|||||||
|
|
||||||
if (canAppendSSHConfig) {
|
if (canAppendSSHConfig) {
|
||||||
// save the host to the local ssh config file
|
// save the host to the local ssh config file
|
||||||
const hostInConfig = `${host}:${port}` // host format: hostname:port
|
const hostInConfig = `${host}-${port}` // host format: hostname-port
|
||||||
|
const privateKeyPath = this.user.getUserPrivateKeyPath();
|
||||||
const newSShConfigContent =
|
const newSShConfigContent =
|
||||||
`\nHost ${hostInConfig}\n HostName ${host}\n Port ${port}\n User ${username}\n PreferredAuthentications publickey\n IdentityFile ~/.ssh/id_rsa\n `;
|
`\nHost ${hostInConfig}\n HostName ${host}\n Port ${port}\n User ${username}\n PreferredAuthentications publickey\n IdentityFile ${privateKeyPath}\n `;
|
||||||
fs.writeFileSync(sshConfigPath, newSShConfigContent, { encoding: 'utf8', flag: 'a' });
|
fs.writeFileSync(sshConfigPath, newSShConfigContent, { encoding: 'utf8', flag: 'a' });
|
||||||
console.log('Host registered in local ssh config');
|
console.log('Host registered in local ssh config');
|
||||||
}
|
}
|
||||||
@@ -141,8 +142,9 @@ export default class RemoteContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
openRemoteFolder(host: string, path: string): void {
|
openRemoteFolder(host: string, username:string ,port:number, path: string): void {
|
||||||
const command = `code --remote ssh-remote+${host} ${path} --reuse-window`
|
var host = `${host}-${port}`
|
||||||
|
const command = `code --remote ssh-remote+${username}@${host} ${path} --reuse-window`
|
||||||
let terminal = vscode.window.activeTerminal || vscode.window.createTerminal(`Ext Terminal`);
|
let terminal = vscode.window.activeTerminal || vscode.window.createTerminal(`Ext Terminal`);
|
||||||
terminal.show(true);
|
terminal.show(true);
|
||||||
terminal.sendText(command);
|
terminal.sendText(command);
|
||||||
|
Reference in New Issue
Block a user