refactor: change name: host->hostname
This commit is contained in:
		@@ -78,7 +78,7 @@ export default class RemoteContainer {
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  async storeHostInfo(host: string, port: number, username: string): Promise<void> {
 | 
			
		||||
  async storeHostInfo(hostname: string, port: number, username: string): Promise<void> {
 | 
			
		||||
    const sshConfigPath = path.join(os.homedir(), '.ssh', 'config');
 | 
			
		||||
    // check if the host and related info exist in local ssh config file before saving
 | 
			
		||||
    var canAppendSSHConfig = true
 | 
			
		||||
@@ -86,8 +86,8 @@ export default class RemoteContainer {
 | 
			
		||||
      var reader = rd.createInterface(fs.createReadStream(sshConfigPath))
 | 
			
		||||
 | 
			
		||||
      for await (const line of reader) {
 | 
			
		||||
        // host format: hostname:port
 | 
			
		||||
        if (line.includes(`Host ${host}-${port}`)) {
 | 
			
		||||
        // host format: hostname-port
 | 
			
		||||
        if (line.includes(`Host ${hostname}-${port}`)) {
 | 
			
		||||
          // the container ssh info exists
 | 
			
		||||
          canAppendSSHConfig = false
 | 
			
		||||
          break;
 | 
			
		||||
@@ -97,10 +97,10 @@ export default class RemoteContainer {
 | 
			
		||||
 | 
			
		||||
    if (canAppendSSHConfig) {
 | 
			
		||||
      // save the host to the local ssh config file 
 | 
			
		||||
      const hostInConfig = `${host}-${port}` // host format: hostname-port
 | 
			
		||||
      const host = `${hostname}-${port}` // host: hostname-port
 | 
			
		||||
      const privateKeyPath = this.user.getUserPrivateKeyPath();
 | 
			
		||||
      const newSShConfigContent =
 | 
			
		||||
        `\nHost ${hostInConfig}\n  HostName ${host}\n  Port ${port}\n  User ${username}\n  PreferredAuthentications publickey\n  IdentityFile ${privateKeyPath}\n  `;
 | 
			
		||||
        `\nHost ${host}\n  HostName ${hostname}\n  Port ${port}\n  User ${username}\n  PreferredAuthentications publickey\n  IdentityFile ${privateKeyPath}\n  `;
 | 
			
		||||
      fs.writeFileSync(sshConfigPath, newSShConfigContent, { encoding: 'utf8', flag: 'a' });
 | 
			
		||||
      console.log('Host registered in local ssh config');
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user