feat: upload user's ssh public key when user login through 'open with vscode' link

This commit is contained in:
Levi Yan
2025-03-03 13:22:01 +08:00
parent e7bac7991f
commit fcf93fe3de

View File

@@ -3,6 +3,7 @@ import QuickAccessTreeProvider from './views/quick-access-tree';
import DSHome from './home';
import RemoteContainer, { openProjectWithoutLogging } from './remote-container';
import User from './user';
import DevstarAPIHandler from './devstar-api';
export class DevStarExtension {
user: User;
@@ -12,6 +13,7 @@ export class DevStarExtension {
constructor(private context: vscode.ExtensionContext) {
this.user = new User(context);
this.remoteContainer = new RemoteContainer(this.user);
this.dsHome = new DSHome(context);
const handler = vscode.window.registerUriHandler({
handleUri: async (uri: vscode.Uri) => {
@@ -36,6 +38,15 @@ export class DevStarExtension {
this.user.setUserTokenToLocal(access_token)
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)
} else if (devstar_username === this.user.getUsernameFromLocal()) {
// 如果同用户已经登录,则忽略;
@@ -49,11 +60,19 @@ export class DevStarExtension {
this.user.setUserTokenToLocal(access_token);
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)
} else if (selection === 'No') {
await openProjectWithoutLogging(container_host, container_port, container_username, project_path);
}
}
} else {
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.startDevStarHome();