feat: update and get local user private key path
This commit is contained in:
@@ -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()
|
||||||
})
|
})
|
||||||
|
12
src/user.ts
12
src/user.ts
@@ -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);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user