Compare commits
10 Commits
b713e4515a
...
781518976e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
781518976e | ||
|
|
c18fc24016 | ||
|
|
41b97301f7 | ||
|
|
1afb9a8085 | ||
|
|
548ccdc575 | ||
|
|
6e75693220 | ||
|
|
ed7ee8cce3 | ||
|
|
12e950bf3e | ||
|
|
4ab517bc44 | ||
|
|
353790d693 |
@@ -2,7 +2,7 @@
|
||||
"name": "devstar",
|
||||
"displayName": "%displayName%",
|
||||
"description": "%description%",
|
||||
"version": "0.3.8",
|
||||
"version": "0.3.9",
|
||||
"keywords": [],
|
||||
"publisher": "mengning",
|
||||
"engines": {
|
||||
|
||||
@@ -21,7 +21,7 @@ export default class DevstarAPIHandler {
|
||||
constructor(devstarDomainURL?: string) {
|
||||
if (devstarDomainURL == undefined || devstarDomainURL == "") {
|
||||
// 获取domain
|
||||
const devstarDomainFromUserConfig = utils.devstarDomain()
|
||||
const devstarDomainFromUserConfig: string | undefined = utils.devstarDomain()
|
||||
if (undefined == devstarDomainFromUserConfig || "" == devstarDomainFromUserConfig) {
|
||||
this.devstarDomain = "https://devstar.cn";
|
||||
} else {
|
||||
@@ -29,7 +29,7 @@ export default class DevstarAPIHandler {
|
||||
}
|
||||
} else {
|
||||
// open with vscode传入
|
||||
this.devstarDomain = devstarDomainURL
|
||||
this.devstarDomain = devstarDomainURL.endsWith('/') ? devstarDomainURL.slice(0, -1) : devstarDomainURL
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
26
src/home.ts
26
src/home.ts
@@ -33,15 +33,17 @@ export default class DSHome {
|
||||
this.remoteContainer = new RemoteContainer(user);
|
||||
|
||||
if (devstarDomain != undefined && devstarDomain != "") {
|
||||
this.devstarDomain = devstarDomain
|
||||
this.devstarDomain = devstarDomain.endsWith('/') ? devstarDomain.slice(0, -1) : devstarDomain
|
||||
this.devstarHomePageUrl = this.devstarDomain + "/devstar-home"
|
||||
} else {
|
||||
this.devstarDomain = utils.devstarDomain()
|
||||
}
|
||||
|
||||
if (undefined == this.devstarDomain || "" == this.devstarDomain) {
|
||||
const devstarDomainFromConfig = utils.devstarDomain()
|
||||
if (devstarDomainFromConfig != undefined && devstarDomainFromConfig != "") {
|
||||
this.devstarDomain = devstarDomainFromConfig.endsWith('/') ? devstarDomainFromConfig.slice(0, -1) : devstarDomainFromConfig
|
||||
this.devstarHomePageUrl = this.devstarDomain + "/devstar-home"
|
||||
} else {
|
||||
this.devstarDomain = "https://devstar.cn"
|
||||
this.devstarHomePageUrl = "https://devstar.cn/devstar-home"
|
||||
} else {
|
||||
this.devstarHomePageUrl = this.devstarDomain.endsWith('/') ? this.devstarDomain + "devstar-home" : this.devstarDomain + "/devstar-home"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,12 +55,12 @@ export default class DSHome {
|
||||
this.remoteContainer = remoteContainer
|
||||
}
|
||||
|
||||
setDevstarDomain(devstarDomain: string) {
|
||||
if (undefined == devstarDomain || "" == devstarDomain) {
|
||||
this.devstarDomain = devstarDomain
|
||||
this.devstarHomePageUrl = "https://devstar.cn/devstar-home"
|
||||
} else {
|
||||
setDevstarDomainAndHomePageURL(devstarDomain: string) {
|
||||
if (devstarDomain != undefined && devstarDomain != "") {
|
||||
this.devstarDomain = devstarDomain.endsWith('/') ? devstarDomain.slice(0, -1) : devstarDomain
|
||||
this.devstarHomePageUrl = devstarDomain.endsWith('/') ? this.devstarDomain + "devstar-home" : devstarDomain + "/devstar-home"
|
||||
} else {
|
||||
console.error("devstarDomain is undefined or null")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
106
src/main.ts
106
src/main.ts
@@ -14,11 +14,6 @@ export class DevStarExtension {
|
||||
dsHome: DSHome;
|
||||
|
||||
constructor(private context: vscode.ExtensionContext) {
|
||||
this.user = new User(context);
|
||||
// 只保持一个User实例
|
||||
this.remoteContainer = new RemoteContainer(this.user);
|
||||
this.dsHome = new DSHome(context, this.user);
|
||||
|
||||
// 确定local系统是否为win,如果是,保存powershell版本
|
||||
if (vscode.env.remoteName === undefined) {
|
||||
if (os.platform() === 'win32') {
|
||||
@@ -29,11 +24,40 @@ export class DevStarExtension {
|
||||
}
|
||||
}
|
||||
|
||||
// support for open with vscode in web
|
||||
// 只保持一个User实例
|
||||
|
||||
// 如果global state中devstarDomain的值不为空,则在global state中存储一个键值对为devstarDomain_<sessionId>和devstar domain,并把devstarDomain的值置空.
|
||||
// 这时如果remote窗口需要打开项目,且global state中的devstarDomain_<sessionId>键存在、值不为空,
|
||||
// 则取出其值,并通过参数将devstar domain传递给/openProjectSkippingLoginCheck
|
||||
//
|
||||
// 如果global state中devstarDomain_<sessionId>存在,直接使用
|
||||
|
||||
const devstarDomain_sessionId: string | undefined = context.globalState.get('devstarDomain_' + vscode.env.sessionId)
|
||||
const devstarDomain: string | undefined = context.globalState.get('devstarDomain')
|
||||
if (devstarDomain_sessionId != undefined && devstarDomain_sessionId != "") {
|
||||
this.user = new User(context, devstarDomain_sessionId)
|
||||
this.remoteContainer = new RemoteContainer(this.user);
|
||||
this.dsHome = new DSHome(context, this.user, devstarDomain_sessionId)
|
||||
} else if (devstarDomain != undefined && devstarDomain != "") {
|
||||
console.log('domain in global state', devstarDomain)
|
||||
// global state中存在devstarDomain
|
||||
this.user = new User(context, devstarDomain)
|
||||
this.remoteContainer = new RemoteContainer(this.user);
|
||||
this.dsHome = new DSHome(context, this.user, devstarDomain)
|
||||
|
||||
context.globalState.update('devstarDomain_' + vscode.env.sessionId, devstarDomain)
|
||||
context.globalState.update('devstarDomain', "")
|
||||
} else {
|
||||
this.user = new User(context);
|
||||
this.remoteContainer = new RemoteContainer(this.user);
|
||||
this.dsHome = new DSHome(context, this.user);
|
||||
}
|
||||
|
||||
const handler = vscode.window.registerUriHandler({
|
||||
handleUri: async (uri: vscode.Uri) => {
|
||||
const devstarAPIHandler = new DevstarAPIHandler()
|
||||
|
||||
/**
|
||||
* 支持open with vscode的入口
|
||||
*/
|
||||
if (uri.path === '/openProject') {
|
||||
const params = new URLSearchParams(uri.query);
|
||||
const host = params.get('host');
|
||||
@@ -41,47 +65,62 @@ export class DevStarExtension {
|
||||
const port = params.get('port');
|
||||
const username = params.get('username');
|
||||
const path = params.get('path');
|
||||
const access_token = params.get('access_token');
|
||||
const devstar_username = params.get('devstar_username');
|
||||
const accessToken = params.get('access_token');
|
||||
const devstarUsername = params.get('devstar_username');
|
||||
const devstarDomain = params.get('devstar_domain');
|
||||
|
||||
if (host && hostname && port && username && path) {
|
||||
const container_host = host;
|
||||
const container_hostname = hostname
|
||||
const container_port = parseInt(port, 10);
|
||||
const container_username = username;
|
||||
const project_path = decodeURIComponent(path);
|
||||
const containerHost = host;
|
||||
const containerHostname = hostname
|
||||
const containerPort = parseInt(port, 10);
|
||||
const containerUsername = username;
|
||||
const projectPath = decodeURIComponent(path);
|
||||
|
||||
if (access_token && devstar_username) {
|
||||
if (!this.user.isLogged()) {
|
||||
if (accessToken && devstarUsername && devstarDomain) {
|
||||
// 修改user、remote-container、home中的devstar domain和hostname
|
||||
this.user.setDevstarDomain(devstarDomain)
|
||||
this.remoteContainer.setUser(this.user)
|
||||
this.dsHome.setDevstarDomainAndHomePageURL(devstarDomain)
|
||||
this.dsHome.setUser(this.user)
|
||||
this.dsHome.setRemoteContainer(this.remoteContainer)
|
||||
vscode.commands.executeCommand('devstar.showHome');
|
||||
|
||||
// 将devstar domain存在global state中
|
||||
context.globalState.update('devstarDomain', devstarDomain)
|
||||
|
||||
if (!await this.user.isLogged()) {
|
||||
// 如果没有用户登录,则直接登录;
|
||||
const res = await this.user.login(access_token, devstar_username)
|
||||
const res = await this.user.login(accessToken, devstarUsername)
|
||||
if (res === 'ok') {
|
||||
await this.remoteContainer.firstOpenProject(container_host, container_hostname, container_port, container_username, project_path, this.context)
|
||||
await this.remoteContainer.firstOpenProject(containerHost, containerHostname, containerPort, containerUsername, projectPath, this.context)
|
||||
}
|
||||
} else if (devstar_username === this.user.getUsernameFromLocal()) {
|
||||
} else if (devstarUsername === this.user.getUsernameFromLocal()) {
|
||||
// 如果同用户已经登录,则忽略,直接打开项目
|
||||
await this.remoteContainer.firstOpenProject(container_host, container_hostname, container_port, container_username, project_path, this.context)
|
||||
await this.remoteContainer.firstOpenProject(containerHost, containerHostname, containerPort, containerUsername, projectPath, this.context)
|
||||
} else {
|
||||
// 如果不是同用户,可以选择切换用户,或者不切换登录用户,直接打开容器
|
||||
const selection = await vscode.window.showWarningMessage(`已登录用户:${this.user.getUsernameFromLocal()},是否切换用户?`,
|
||||
'Yes', 'No',);
|
||||
if (selection === 'Yes') {
|
||||
// 如果没有用户登录,则直接登录;
|
||||
const res = await this.user.login(access_token, devstar_username)
|
||||
const res = await this.user.login(accessToken, devstarUsername)
|
||||
if (res === 'ok') {
|
||||
await this.remoteContainer.firstOpenProject(container_host, container_hostname, container_port, container_username, project_path, this.context)
|
||||
await this.remoteContainer.firstOpenProject(containerHost, containerHostname, containerPort, containerUsername, projectPath, this.context)
|
||||
}
|
||||
} else if (selection === 'No') {
|
||||
await openProjectWithoutLogging(container_host, container_port, container_username, project_path);
|
||||
await openProjectWithoutLogging(containerHost, containerPort, containerUsername, projectPath);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
await openProjectWithoutLogging(container_host, container_port, container_username, project_path);
|
||||
await openProjectWithoutLogging(containerHost, containerPort, containerUsername, projectPath);
|
||||
}
|
||||
} else {
|
||||
vscode.window.showErrorMessage('Missing required parameters.');
|
||||
}
|
||||
} else if (uri.path === "/openProjectSkippingLoginCheck") {
|
||||
/**
|
||||
* 支持remote打开local窗口后再打开项目的入口
|
||||
*/
|
||||
// 仅有已登录、不用改变登录状态时,用此流程
|
||||
const params = new URLSearchParams(uri.query);
|
||||
const host = params.get('host');
|
||||
@@ -89,6 +128,7 @@ export class DevStarExtension {
|
||||
const port = params.get('port');
|
||||
const username = params.get('username');
|
||||
const path = params.get('path');
|
||||
const devstarDomain = params.get('devstar_domain')
|
||||
|
||||
if (host && hostname && port && username && path) {
|
||||
const container_host = host;
|
||||
@@ -97,7 +137,23 @@ export class DevStarExtension {
|
||||
const container_username = username;
|
||||
const project_path = decodeURIComponent(path);
|
||||
|
||||
if (devstarDomain != undefined && devstarDomain != "") {
|
||||
// 修改user、remote-container、home中的devstar domain和hostname
|
||||
this.user.setDevstarDomain(devstarDomain)
|
||||
this.remoteContainer.setUser(this.user)
|
||||
this.dsHome.setDevstarDomainAndHomePageURL(devstarDomain)
|
||||
this.dsHome.setUser(this.user)
|
||||
this.dsHome.setRemoteContainer(this.remoteContainer)
|
||||
vscode.commands.executeCommand('devstar.showHome');
|
||||
|
||||
// 将devstar domain存在global state中
|
||||
context.globalState.update('devstarDomain', devstarDomain)
|
||||
|
||||
await this.remoteContainer.firstOpenProject(container_host, container_hostname, container_port, container_username, project_path, this.context)
|
||||
} else {
|
||||
// devstarDomain参数不存在,则不存储,使用默认用户配置
|
||||
await this.remoteContainer.firstOpenProject(container_host, container_hostname, container_port, container_username, project_path, this.context)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,11 +37,18 @@ export default class RemoteContainer {
|
||||
vscode.commands.executeCommand('workbench.action.terminal.newLocal').then(() => {
|
||||
const terminal = vscode.window.terminals[vscode.window.terminals.length - 1];
|
||||
if (terminal) {
|
||||
let devstarDomain: string | undefined = context.globalState.get("devstarDomain_" + vscode.env.sessionId)
|
||||
if (devstarDomain == undefined || devstarDomain == "")
|
||||
devstarDomain = undefined
|
||||
|
||||
// vscode协议
|
||||
// 根据系统+命令行版本确定命令
|
||||
const semver = require('semver')
|
||||
const powershellVersion = context.globalState.get('powershellVersion')
|
||||
const powershell_semver_compatible_version = semver.coerce(powershellVersion)
|
||||
|
||||
if (devstarDomain === undefined) {
|
||||
// 不传递devstarDomain
|
||||
if (powershellVersion === undefined)
|
||||
terminal.sendText(`code --new-window && code --open-url "vscode://mengning.devstar/openProjectSkippingLoginCheck?host=${host}&hostname=${hostname}&port=${port}&username=${username}&path=${path}"`)
|
||||
else if (semver.satisfies(powershell_semver_compatible_version, ">=5.1.26100")) {
|
||||
@@ -51,6 +58,17 @@ export default class RemoteContainer {
|
||||
// win & powershell < 5.1.26100.0
|
||||
terminal.sendText(`code --new-window && code --open-url "vscode://mengning.devstar/openProjectSkippingLoginCheck?host=${host}&hostname=${hostname}&port=${port}&username=${username}&path=${path}"`)
|
||||
}
|
||||
} else {
|
||||
if (powershellVersion === undefined)
|
||||
terminal.sendText(`code --new-window && code --open-url "vscode://mengning.devstar/openProjectSkippingLoginCheck?host=${host}&hostname=${hostname}&port=${port}&username=${username}&path=${path}&devstar_domain=${devstarDomain}"`)
|
||||
else if (semver.satisfies(powershell_semver_compatible_version, ">=5.1.26100")) {
|
||||
// win & powershell >= 5.1.26100.0
|
||||
terminal.sendText(`code --new-window ; code --% --open-url "vscode://mengning.devstar/openProjectSkippingLoginCheck?host=${host}&hostname=${hostname}&port=${port}&username=${username}&path=${path}&devstar_domain=${devstarDomain}"`)
|
||||
} else {
|
||||
// win & powershell < 5.1.26100.0
|
||||
terminal.sendText(`code --new-window && code --open-url "vscode://mengning.devstar/openProjectSkippingLoginCheck?host=${host}&hostname=${hostname}&port=${port}&username=${username}&path=${path}&devstar_domain=${devstarDomain}"`)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
|
||||
100
src/user.ts
100
src/user.ts
@@ -3,7 +3,7 @@ import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import * as fs from 'fs';
|
||||
import DevstarAPIHandler from './devstar-api';
|
||||
import { showErrorNotification } from './utils';
|
||||
import * as utils from './utils';
|
||||
const {
|
||||
generateKeyPairSync,
|
||||
createHash
|
||||
@@ -12,12 +12,11 @@ const sshpk = require('sshpk');
|
||||
|
||||
export default class User {
|
||||
private context: vscode.ExtensionContext;
|
||||
private username: string | undefined;
|
||||
private userToken: string | undefined;
|
||||
private usernameKey: string = 'devstarUsername'
|
||||
private userTokenKey: string = 'devstarUserToken'
|
||||
// 修改devstarDomain会影响hostname, username key, user token key
|
||||
private devstarDomain: string;
|
||||
private devstarHostname: string;
|
||||
private usernameKey: string; // devstarUsername_<devstarDomain>
|
||||
private userTokenKey: string; // devstarUserToken_<devstarDomain>
|
||||
|
||||
/**
|
||||
* devstarDomain由配置项提供
|
||||
@@ -34,35 +33,41 @@ export default class User {
|
||||
|
||||
constructor(context: vscode.ExtensionContext, devstarDomain?: string) {
|
||||
this.context = context;
|
||||
this.username = this.context.globalState.get(this.usernameKey);
|
||||
this.userToken = this.context.globalState.get(this.userTokenKey);
|
||||
|
||||
// 提取devstar domain的主域名,用于本地ssh key的命名
|
||||
if (devstarDomain != undefined && devstarDomain != "") {
|
||||
// open with vscode链接提供域名
|
||||
this.devstarDomain = devstarDomain
|
||||
this.devstarDomain = devstarDomain.endsWith('/') ? devstarDomain.slice(0, -1) : devstarDomain
|
||||
let parsedUrl = new URL(devstarDomain);
|
||||
this.devstarHostname = parsedUrl.hostname.replace(/\./g, '_'); //提取hostname,并用下划线替换.
|
||||
} else {
|
||||
const devstarDomainFromConfig: string | undefined = utils.devstarDomain();
|
||||
if (devstarDomainFromConfig != undefined && devstarDomainFromConfig != "") {
|
||||
// 用户配置项提供域名
|
||||
let devstarDomainFromConfig: string | undefined;
|
||||
let devstarDomainURL: string;
|
||||
devstarDomainFromConfig = vscode.workspace.getConfiguration('devstar').get('devstarDomain')
|
||||
// 如果没有配置devstar domain,则默认domain为https://devstar.cn
|
||||
devstarDomainURL = (devstarDomainFromConfig === undefined || devstarDomainFromConfig === "") ? 'https://devstar.cn' : devstarDomainFromConfig;
|
||||
this.devstarDomain = devstarDomainURL
|
||||
let parsedUrl = new URL(devstarDomainURL);
|
||||
this.devstarDomain = devstarDomainFromConfig.endsWith('/') ? devstarDomainFromConfig.slice(0, -1) : devstarDomainFromConfig
|
||||
let parsedUrl = new URL(this.devstarDomain);
|
||||
this.devstarHostname = parsedUrl.hostname.replace(/\./g, '_'); //提取hostname,并用下划线替换.
|
||||
} else {
|
||||
// 如果没有配置devstar domain,则默认domain为https://devstar.cn
|
||||
this.devstarDomain = "https://devstar.cn"
|
||||
this.devstarHostname = "devstar_cn"
|
||||
}
|
||||
}
|
||||
|
||||
setDevstarDomainAndHostname(devstarDomain: string) {
|
||||
this.usernameKey = "devstarUsername_" + this.devstarDomain
|
||||
this.userTokenKey = "devstarUserToken_" + this.devstarDomain
|
||||
}
|
||||
|
||||
setDevstarDomain(devstarDomain: string) {
|
||||
// 修改devstar domain会影响hostname、usertoken key、username key
|
||||
if (devstarDomain != "") {
|
||||
this.devstarDomain = devstarDomain
|
||||
this.devstarDomain = devstarDomain.endsWith('/') ? devstarDomain.slice(0, -1) : devstarDomain
|
||||
const parsedUrl = new URL(devstarDomain)
|
||||
this.devstarHostname = parsedUrl.hostname.replace(/\./g, '_');
|
||||
this.usernameKey = "devstarUsername_" + this.devstarDomain
|
||||
this.userTokenKey = "devstarUserToken_" + this.devstarDomain
|
||||
} else {
|
||||
console.error(vscode.l10n.t("devstar domain is null"))
|
||||
console.error("devstar domain is null")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,8 +82,7 @@ export default class User {
|
||||
const res = await devstarAPIHandler.verifyToken(token, username)
|
||||
if (!res) {
|
||||
throw new Error('Token verification failed')
|
||||
}
|
||||
|
||||
} else {
|
||||
// token与用户名验证通过
|
||||
// 插件登录:存储token与用户名
|
||||
this.setUserTokenToLocal(token)
|
||||
@@ -97,9 +101,11 @@ export default class User {
|
||||
|
||||
vscode.window.showInformationMessage(vscode.l10n.t('User login successfully!'))
|
||||
return 'ok'
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
await showErrorNotification('用户登录失败!')
|
||||
await utils.showErrorNotification('用户登录失败!')
|
||||
return 'login failed'
|
||||
}
|
||||
}
|
||||
@@ -110,34 +116,34 @@ export default class User {
|
||||
vscode.window.showInformationMessage(vscode.l10n.t("User has logged out!"))
|
||||
}
|
||||
|
||||
public isLogged() {
|
||||
var existUsername = false;
|
||||
var existUserToken = false;
|
||||
if (this.username != undefined && this.username != '') {
|
||||
existUsername = true;
|
||||
}
|
||||
if (this.userToken != undefined && this.userToken != '') {
|
||||
existUserToken = true;
|
||||
}
|
||||
public async isLogged(): Promise<boolean> {
|
||||
const username: string|undefined = this.context.globalState.get(this.usernameKey)
|
||||
const userToken: string|undefined = this.context.globalState.get(this.userTokenKey)
|
||||
if ((username != undefined && username != '') && (userToken != undefined && userToken != '')) {
|
||||
const devstarAPIHandler = new DevstarAPIHandler(this.devstarDomain)
|
||||
|
||||
if (existUsername && existUserToken) {
|
||||
const res = await devstarAPIHandler.verifyToken(userToken, username)
|
||||
if (!res) {
|
||||
console.error("username or token is error")
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public getUsernameFromLocal(): string | undefined {
|
||||
return this.username;
|
||||
return this.context.globalState.get(this.usernameKey);
|
||||
}
|
||||
|
||||
public getUserTokenFromLocal(): string | undefined {
|
||||
return this.userToken;
|
||||
return this.context.globalState.get(this.userTokenKey);
|
||||
}
|
||||
|
||||
public setUsernameToLocal(username: string) {
|
||||
this.context.globalState.update(this.usernameKey, username);
|
||||
this.username = username;
|
||||
if (username !== "") {
|
||||
console.log('Username has been stored.')
|
||||
} else {
|
||||
@@ -147,7 +153,6 @@ export default class User {
|
||||
|
||||
public setUserTokenToLocal(userToken: string) {
|
||||
this.context.globalState.update(this.userTokenKey, userToken)
|
||||
this.userToken = userToken
|
||||
if (userToken !== "") {
|
||||
console.log('Token has been stored.');
|
||||
} else {
|
||||
@@ -164,19 +169,23 @@ export default class User {
|
||||
}
|
||||
|
||||
public getUserPrivateKeyPath(): string {
|
||||
if (!this.isLogged) {
|
||||
if (!this.isLogged()) {
|
||||
return '';
|
||||
} else {
|
||||
const username: string|undefined = this.context.globalState.get(this.usernameKey)
|
||||
// islogged为true,username不为空
|
||||
return path.join(os.homedir(), '.ssh', `id_rsa_${username}_${this.devstarHostname}`)
|
||||
}
|
||||
|
||||
return path.join(os.homedir(), '.ssh', `id_rsa_${this.username}_${this.devstarHostname}`)
|
||||
}
|
||||
|
||||
public getUserPublicKeyPath(): string {
|
||||
if (!this.isLogged) {
|
||||
if (!this.isLogged()) {
|
||||
return '';
|
||||
} else {
|
||||
const username: string|undefined = this.context.globalState.get(this.usernameKey)
|
||||
// islogged为true,username不为空
|
||||
return path.join(os.homedir(), '.ssh', `id_rsa_${username}_${this.devstarHostname}.pub`)
|
||||
}
|
||||
|
||||
return path.join(os.homedir(), '.ssh', `id_rsa_${this.username}_${this.devstarHostname}.pub`)
|
||||
}
|
||||
|
||||
public existUserPublicKey(): boolean {
|
||||
@@ -208,6 +217,12 @@ export default class User {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!await this.isLogged()) {
|
||||
// 如果用户没有登录,则拒绝创建ssh key
|
||||
console.error("User hasn't been logged, refuse to craete user ssh key")
|
||||
return;
|
||||
}
|
||||
|
||||
const {
|
||||
publicKey,
|
||||
privateKey,
|
||||
@@ -244,7 +259,8 @@ export default class User {
|
||||
this.updateLocalUserPrivateKeyPath(this.getUserPrivateKeyPath())
|
||||
console.log(`Update local user private key path.`)
|
||||
} catch (error) {
|
||||
console.error(`Failed to write public/private key into the user(${this.username}) ssh public/key file: `, error);
|
||||
const username: string|undefined = this.context.globalState.get(this.usernameKey)
|
||||
console.error(`Failed to write public/private key into the user(${username}) ssh public/key file: `, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user