mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-23 14:56:07 +08:00
修复删除私钥
This commit is contained in:
parent
5bb1afe5c6
commit
cb12d8ffec
|
@ -14,7 +14,10 @@ export default class SshKeyService {
|
||||||
|
|
||||||
private generatePrivateKeyFile(alias: string, key: string): void {
|
private generatePrivateKeyFile(alias: string, key: string): void {
|
||||||
try {
|
try {
|
||||||
fs.writeFileSync(`${this.sshPath}/${alias}`, key, { encoding: 'utf8' });
|
fs.writeFileSync(`${this.sshPath}/${alias}`, key, {
|
||||||
|
encoding: 'utf8',
|
||||||
|
mode: '400',
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error('生成私钥文件失败', error);
|
this.logger.error('生成私钥文件失败', error);
|
||||||
}
|
}
|
||||||
|
@ -37,7 +40,6 @@ export default class SshKeyService {
|
||||||
for (const config of configs) {
|
for (const config of configs) {
|
||||||
fs.appendFileSync(this.sshConfigFilePath, config, {
|
fs.appendFileSync(this.sshConfigFilePath, config, {
|
||||||
encoding: 'utf8',
|
encoding: 'utf8',
|
||||||
mode: '400',
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -47,10 +49,13 @@ export default class SshKeyService {
|
||||||
|
|
||||||
private removeSshConfig(config: string) {
|
private removeSshConfig(config: string) {
|
||||||
try {
|
try {
|
||||||
fs.readFileSync(this.sshConfigFilePath, { encoding: 'utf8' }).replace(
|
const data = fs
|
||||||
config,
|
.readFileSync(this.sshConfigFilePath, { encoding: 'utf8' })
|
||||||
'',
|
.replace(config, '')
|
||||||
);
|
.replace(/\n\n+/, '\n\n');
|
||||||
|
fs.writeFileSync(this.sshConfigFilePath, data, {
|
||||||
|
encoding: 'utf8',
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error(`删除ssh配置文件${config}失败`, error);
|
this.logger.error(`删除ssh配置文件${config}失败`, error);
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,7 @@ export default class SubscriptionService {
|
||||||
|
|
||||||
private formatCommand(doc: Subscription, url?: string) {
|
private formatCommand(doc: Subscription, url?: string) {
|
||||||
let command = 'ql ';
|
let command = 'ql ';
|
||||||
let _url = url || doc.url;
|
let _url = url || this.formatUrl(doc).url;
|
||||||
const { type, whitelist, blacklist, dependences, branch } = doc;
|
const { type, whitelist, blacklist, dependences, branch } = doc;
|
||||||
if (type === 'file') {
|
if (type === 'file') {
|
||||||
command += `raw "${_url}"`;
|
command += `raw "${_url}"`;
|
||||||
|
@ -108,27 +108,35 @@ export default class SubscriptionService {
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleTask(doc: Subscription, needCreate = true, needAddKey = true) {
|
private formatUrl(doc: Subscription) {
|
||||||
let url = doc.url;
|
let url = doc.url;
|
||||||
|
let host = '';
|
||||||
if (doc.type === 'private-repo') {
|
if (doc.type === 'private-repo') {
|
||||||
if (doc.pull_type === 'ssh-key') {
|
if (doc.pull_type === 'ssh-key') {
|
||||||
const host = doc.url!.replace(/.*\@([^\:]+)\:.*/, '$1');
|
host = doc.url!.replace(/.*\@([^\:]+)\:.*/, '$1');
|
||||||
url = doc.url!.replace(host, doc.alias);
|
url = doc.url!.replace(host, doc.alias);
|
||||||
if (needAddKey) {
|
|
||||||
this.sshKeyService.addSSHKey(
|
|
||||||
(doc.pull_option as any).private_key,
|
|
||||||
doc.alias,
|
|
||||||
host,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
this.sshKeyService.removeSSHKey(doc.alias, host);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
const host = doc.url!.replace(/.*\:\/\/([^\/]+)\/.*/, '$1');
|
host = doc.url!.replace(/.*\:\/\/([^\/]+)\/.*/, '$1');
|
||||||
const { username, password } = doc.pull_option as any;
|
const { username, password } = doc.pull_option as any;
|
||||||
url = doc.url!.replace(host, `${username}:${password}@${host}`);
|
url = doc.url!.replace(host, `${username}:${password}@${host}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return { url, host };
|
||||||
|
}
|
||||||
|
|
||||||
|
private handleTask(doc: Subscription, needCreate = true, needAddKey = true) {
|
||||||
|
const { url, host } = this.formatUrl(doc);
|
||||||
|
if (doc.type === 'private-repo' && doc.pull_type === 'ssh-key') {
|
||||||
|
if (needAddKey) {
|
||||||
|
this.sshKeyService.addSSHKey(
|
||||||
|
(doc.pull_option as any).private_key,
|
||||||
|
doc.alias,
|
||||||
|
host,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
this.sshKeyService.removeSSHKey(doc.alias, host);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
doc.command = this.formatCommand(doc, url as string);
|
doc.command = this.formatCommand(doc, url as string);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user