From 5a01c41bbb940820f8624a7faec7078f86cff278 Mon Sep 17 00:00:00 2001 From: whyour Date: Wed, 1 Jun 2022 00:03:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=A7=81=E9=92=A5=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E5=8C=B9=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/services/sshKey.ts | 18 +++++++++++++----- package.json | 6 +++--- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/back/services/sshKey.ts b/back/services/sshKey.ts index b707d78e..32a16d06 100644 --- a/back/services/sshKey.ts +++ b/back/services/sshKey.ts @@ -23,6 +23,13 @@ export default class SshKeyService { } } + private getConfigRegx(alias: string) { + return new RegExp( + `Host ${alias}\n.*[^StrictHostKeyChecking]*.*[\n]*.*StrictHostKeyChecking no`, + 'g', + ); + } + private removePrivateKeyFile(alias: string): void { try { fs.unlinkSync(`${this.sshPath}/${alias}`); @@ -47,24 +54,25 @@ export default class SshKeyService { } } - private removeSshConfig(config: string) { + private removeSshConfig(alias: string) { try { + const configRegx = this.getConfigRegx(alias); const data = fs .readFileSync(this.sshConfigFilePath, { encoding: 'utf8' }) - .replace(config, '') - .replace(/\n\n+/, '\n\n'); + .replace(configRegx, '') + .replace(/\n[\n]+/g, '\n'); fs.writeFileSync(this.sshConfigFilePath, data, { encoding: 'utf8', }); } catch (error) { - this.logger.error(`删除ssh配置文件${config}失败`, error); + this.logger.error(`删除ssh配置文件${alias}失败`, error); } } public addSSHKey(key: string, alias: string, host: string): void { this.generatePrivateKeyFile(alias, key); const config = this.generateSingleSshConfig(alias, host); - this.removeSshConfig(config); + this.removeSshConfig(alias); this.generateSshConfig([config]); } diff --git a/package.json b/package.json index 9bd198b0..2e5f8ef3 100644 --- a/package.json +++ b/package.json @@ -40,8 +40,8 @@ }, "dependencies": { "@otplib/preset-default": "^12.0.1", - "@sentry/node": "^6.18.1", - "@sentry/tracing": "^6.18.1", + "@sentry/node": "^7.0.0", + "@sentry/tracing": "^7.0.0", "body-parser": "^1.19.2", "celebrate": "^15.0.1", "chokidar": "^3.5.3", @@ -77,7 +77,7 @@ "@ant-design/icons": "^4.7.0", "@ant-design/pro-layout": "^6.33.1", "@monaco-editor/react": "^4.3.1", - "@sentry/react": "^6.18.1", + "@sentry/react": "^7.0.0", "@types/body-parser": "^1.19.2", "@types/cors": "^2.8.12", "@types/express": "^4.17.13",