feat: update and get local user private key path

This commit is contained in:
Levi Yan
2025-05-06 22:52:54 +08:00
parent f22c1c231b
commit d5487fa6b7
2 changed files with 14 additions and 0 deletions

View File

@@ -115,6 +115,8 @@ export class DevStarExtension {
fs.unlinkSync(this.user.getUserPublicKeyPath()) fs.unlinkSync(this.user.getUserPublicKeyPath())
} }
console.log("User's ssh key has been deleted!") console.log("User's ssh key has been deleted!")
// 更新local user private key path
this.user.updateLocalUserPrivateKeyPath("")
// 退出登录 // 退出登录
this.user.logout() this.user.logout()
}) })

View File

@@ -16,6 +16,7 @@ export default class User {
private userToken: string | undefined; private userToken: string | undefined;
private usernameKey: string = 'devstarUsername' private usernameKey: string = 'devstarUsername'
private userTokenKey: string = 'devstarUserToken' private userTokenKey: string = 'devstarUserToken'
private localUserPrivateKeyPath: string = ''
private devstarHostname: string; private devstarHostname: string;
constructor(context: vscode.ExtensionContext) { 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 { public getUserPrivateKeyPath(): string {
if (!this.isLogged) { if (!this.isLogged) {
return ''; return '';
@@ -187,6 +196,9 @@ export default class User {
// limit the permission of private key to prevent that the private key not works // limit the permission of private key to prevent that the private key not works
await fs.chmodSync(this.getUserPrivateKeyPath(), 0o600) await fs.chmodSync(this.getUserPrivateKeyPath(), 0o600)
console.log(`User's ssh key has been created.`) 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) { } catch (error) {
console.error("Failed to write public/private key into the default ssh public/key file: ", error); console.error("Failed to write public/private key into the default ssh public/key file: ", error);
} }