diff --git a/src/main.ts b/src/main.ts index 4550355..3b2fc72 100644 --- a/src/main.ts +++ b/src/main.ts @@ -115,6 +115,8 @@ export class DevStarExtension { fs.unlinkSync(this.user.getUserPublicKeyPath()) } console.log("User's ssh key has been deleted!") + // 更新local user private key path + this.user.updateLocalUserPrivateKeyPath("") // 退出登录 this.user.logout() }) diff --git a/src/user.ts b/src/user.ts index 2264002..7a7fbd2 100644 --- a/src/user.ts +++ b/src/user.ts @@ -16,6 +16,7 @@ export default class User { private userToken: string | undefined; private usernameKey: string = 'devstarUsername' private userTokenKey: string = 'devstarUserToken' + private localUserPrivateKeyPath: string = '' private devstarHostname: string; constructor(context: vscode.ExtensionContext) { @@ -118,6 +119,14 @@ export default class User { } } + public updateLocalUserPrivateKeyPath(localUserPrivateKeyPath: string) { + this.context.globalState.update('localUserPrivateKeyPath', localUserPrivateKeyPath) + } + + public getLocalUserPrivateKeyPath(): undefined | string { + return this.context.globalState.get('localUserPrivateKeyPath') + } + public getUserPrivateKeyPath(): string { if (!this.isLogged) { return ''; @@ -187,6 +196,9 @@ export default class User { // limit the permission of private key to prevent that the private key not works await fs.chmodSync(this.getUserPrivateKeyPath(), 0o600) console.log(`User's ssh key has been created.`) + // 更新local user private key path + this.updateLocalUserPrivateKeyPath(this.getUserPrivateKeyPath()) + console.log(`Update local user private key path.`) } catch (error) { console.error("Failed to write public/private key into the default ssh public/key file: ", error); }