mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-23 23:06:06 +08:00
修复私钥配置文件匹配
This commit is contained in:
parent
d43cee53c9
commit
6116aa6d12
|
@ -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 {
|
private removePrivateKeyFile(alias: string): void {
|
||||||
try {
|
try {
|
||||||
fs.unlinkSync(`${this.sshPath}/${alias}`);
|
fs.unlinkSync(`${this.sshPath}/${alias}`);
|
||||||
|
@ -47,24 +54,25 @@ export default class SshKeyService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private removeSshConfig(config: string) {
|
private removeSshConfig(alias: string) {
|
||||||
try {
|
try {
|
||||||
|
const configRegx = this.getConfigRegx(alias);
|
||||||
const data = fs
|
const data = fs
|
||||||
.readFileSync(this.sshConfigFilePath, { encoding: 'utf8' })
|
.readFileSync(this.sshConfigFilePath, { encoding: 'utf8' })
|
||||||
.replace(config, '')
|
.replace(configRegx, '')
|
||||||
.replace(/\n\n+/, '\n\n');
|
.replace(/\n[\n]+/g, '\n');
|
||||||
fs.writeFileSync(this.sshConfigFilePath, data, {
|
fs.writeFileSync(this.sshConfigFilePath, data, {
|
||||||
encoding: 'utf8',
|
encoding: 'utf8',
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error(`删除ssh配置文件${config}失败`, error);
|
this.logger.error(`删除ssh配置文件${alias}失败`, error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public addSSHKey(key: string, alias: string, host: string): void {
|
public addSSHKey(key: string, alias: string, host: string): void {
|
||||||
this.generatePrivateKeyFile(alias, key);
|
this.generatePrivateKeyFile(alias, key);
|
||||||
const config = this.generateSingleSshConfig(alias, host);
|
const config = this.generateSingleSshConfig(alias, host);
|
||||||
this.removeSshConfig(config);
|
this.removeSshConfig(alias);
|
||||||
this.generateSshConfig([config]);
|
this.generateSshConfig([config]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,8 +40,8 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@otplib/preset-default": "^12.0.1",
|
"@otplib/preset-default": "^12.0.1",
|
||||||
"@sentry/node": "^6.18.1",
|
"@sentry/node": "^7.0.0",
|
||||||
"@sentry/tracing": "^6.18.1",
|
"@sentry/tracing": "^7.0.0",
|
||||||
"body-parser": "^1.19.2",
|
"body-parser": "^1.19.2",
|
||||||
"celebrate": "^15.0.1",
|
"celebrate": "^15.0.1",
|
||||||
"chokidar": "^3.5.3",
|
"chokidar": "^3.5.3",
|
||||||
|
@ -77,7 +77,7 @@
|
||||||
"@ant-design/icons": "^4.7.0",
|
"@ant-design/icons": "^4.7.0",
|
||||||
"@ant-design/pro-layout": "^6.33.1",
|
"@ant-design/pro-layout": "^6.33.1",
|
||||||
"@monaco-editor/react": "^4.3.1",
|
"@monaco-editor/react": "^4.3.1",
|
||||||
"@sentry/react": "^6.18.1",
|
"@sentry/react": "^7.0.0",
|
||||||
"@types/body-parser": "^1.19.2",
|
"@types/body-parser": "^1.19.2",
|
||||||
"@types/cors": "^2.8.12",
|
"@types/cors": "^2.8.12",
|
||||||
"@types/express": "^4.17.13",
|
"@types/express": "^4.17.13",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user