feat: upload user's ssh public key when user login through 'open with vscode' link
This commit is contained in:
		
							
								
								
									
										22
									
								
								src/main.ts
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								src/main.ts
									
									
									
									
									
								
							@@ -3,6 +3,7 @@ import QuickAccessTreeProvider from './views/quick-access-tree';
 | 
				
			|||||||
import DSHome from './home';
 | 
					import DSHome from './home';
 | 
				
			||||||
import RemoteContainer, { openProjectWithoutLogging } from './remote-container';
 | 
					import RemoteContainer, { openProjectWithoutLogging } from './remote-container';
 | 
				
			||||||
import User from './user';
 | 
					import User from './user';
 | 
				
			||||||
 | 
					import DevstarAPIHandler from './devstar-api';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export class DevStarExtension {
 | 
					export class DevStarExtension {
 | 
				
			||||||
  user: User;
 | 
					  user: User;
 | 
				
			||||||
@@ -12,6 +13,7 @@ export class DevStarExtension {
 | 
				
			|||||||
  constructor(private context: vscode.ExtensionContext) {
 | 
					  constructor(private context: vscode.ExtensionContext) {
 | 
				
			||||||
    this.user = new User(context);
 | 
					    this.user = new User(context);
 | 
				
			||||||
    this.remoteContainer = new RemoteContainer(this.user);
 | 
					    this.remoteContainer = new RemoteContainer(this.user);
 | 
				
			||||||
 | 
					    this.dsHome = new DSHome(context);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const handler = vscode.window.registerUriHandler({
 | 
					    const handler = vscode.window.registerUriHandler({
 | 
				
			||||||
      handleUri: async (uri: vscode.Uri) => {
 | 
					      handleUri: async (uri: vscode.Uri) => {
 | 
				
			||||||
@@ -36,6 +38,15 @@ export class DevStarExtension {
 | 
				
			|||||||
                this.user.setUserTokenToLocal(access_token)
 | 
					                this.user.setUserTokenToLocal(access_token)
 | 
				
			||||||
                this.user.setUsernameToLocal(devstar_username)
 | 
					                this.user.setUsernameToLocal(devstar_username)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                // 检查本地是否有用户所属公钥,没有则创建
 | 
				
			||||||
 | 
					                if (!this.user.existUserPublicKey()) {
 | 
				
			||||||
 | 
					                  await this.user.createUserSSHKey()
 | 
				
			||||||
 | 
					                    .then(async () => {
 | 
				
			||||||
 | 
					                      // 上传公钥
 | 
				
			||||||
 | 
					                      const devstarAPIHandler = new DevstarAPIHandler(this.user)
 | 
				
			||||||
 | 
					                      await devstarAPIHandler.uploadUserPublicKey()
 | 
				
			||||||
 | 
					                    })
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
                await this.remoteContainer.firstOpenProject(container_host, container_port, container_username, project_path)
 | 
					                await this.remoteContainer.firstOpenProject(container_host, container_port, container_username, project_path)
 | 
				
			||||||
              } else if (devstar_username === this.user.getUsernameFromLocal()) {
 | 
					              } else if (devstar_username === this.user.getUsernameFromLocal()) {
 | 
				
			||||||
                // 如果同用户已经登录,则忽略;
 | 
					                // 如果同用户已经登录,则忽略;
 | 
				
			||||||
@@ -49,11 +60,19 @@ export class DevStarExtension {
 | 
				
			|||||||
                  this.user.setUserTokenToLocal(access_token);
 | 
					                  this.user.setUserTokenToLocal(access_token);
 | 
				
			||||||
                  this.user.setUsernameToLocal(devstar_username);
 | 
					                  this.user.setUsernameToLocal(devstar_username);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                  // 检查本地是否有用户所属公钥,没有则创建
 | 
				
			||||||
 | 
					                  if (!this.user.existUserPublicKey()) {
 | 
				
			||||||
 | 
					                    await this.user.createUserSSHKey()
 | 
				
			||||||
 | 
					                      .then(async () => {
 | 
				
			||||||
 | 
					                        // 上传公钥
 | 
				
			||||||
 | 
					                        const devstarAPIHandler = new DevstarAPIHandler(this.user)
 | 
				
			||||||
 | 
					                        await devstarAPIHandler.uploadUserPublicKey()
 | 
				
			||||||
 | 
					                      })
 | 
				
			||||||
 | 
					                  }
 | 
				
			||||||
                  await this.remoteContainer.firstOpenProject(container_host, container_port, container_username, project_path)
 | 
					                  await this.remoteContainer.firstOpenProject(container_host, container_port, container_username, project_path)
 | 
				
			||||||
                } else if (selection === 'No') {
 | 
					                } else if (selection === 'No') {
 | 
				
			||||||
                  await openProjectWithoutLogging(container_host, container_port, container_username, project_path);
 | 
					                  await openProjectWithoutLogging(container_host, container_port, container_username, project_path);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					 | 
				
			||||||
              }
 | 
					              }
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
              await openProjectWithoutLogging(container_host, container_port, container_username, project_path);
 | 
					              await openProjectWithoutLogging(container_host, container_port, container_username, project_path);
 | 
				
			||||||
@@ -74,7 +93,6 @@ export class DevStarExtension {
 | 
				
			|||||||
      )
 | 
					      )
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this.dsHome = new DSHome(context);
 | 
					 | 
				
			||||||
    this.registerGlobalCommands(context);
 | 
					    this.registerGlobalCommands(context);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this.startDevStarHome();
 | 
					    this.startDevStarHome();
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user