pull/101/head
xiaojunnuo 2024-07-08 11:10:08 +08:00
parent bc650a32cd
commit f9c9fce581
1 changed files with 47 additions and 32 deletions

View File

@ -10,7 +10,7 @@ import {
import { SshClient } from '../../lib/ssh';
import { CertInfo, CertReader } from '@certd/plugin-cert';
import * as fs from 'fs';
import {SshAccess} from "../../access";
import { SshAccess } from '../../access';
@IsTaskPlugin({
name: 'uploadCertToHost',
@ -102,18 +102,26 @@ export class UploadCertToHostPlugin extends AbstractTaskPlugin {
this.logger.info('将证书写入本地缓存文件');
const saveCrtPath = certReader.saveToFile('crt');
const saveKeyPath = certReader.saveToFile('key');
this.logger.info('本地文件写入成功');
try {
if (this.copyToThisHost) {
this.logger.info('复制到目标路径');
this.copyFile(saveCrtPath, crtPath);
this.copyFile(saveKeyPath, keyPath);
this.logger.info('证书复制成功crtPath=', crtPath, ',keyPath=', keyPath);
this.logger.info(
'证书复制成功crtPath=',
crtPath,
',keyPath=',
keyPath
);
} else {
if (!accessId) {
throw new Error('主机登录授权配置不能为空');
}
this.logger.info('准备上传到服务器');
const connectConf:SshAccess = await this.accessService.getById(accessId);
this.logger.info('准备上传文件到服务器');
const connectConf: SshAccess = await this.accessService.getById(
accessId
);
const sshClient = new SshClient(this.logger);
await sshClient.uploadFiles({
connectConf,
@ -128,13 +136,20 @@ export class UploadCertToHostPlugin extends AbstractTaskPlugin {
},
],
});
this.logger.info('证书上传成功crtPath=', crtPath, ',keyPath=', keyPath);
this.logger.info(
'证书上传成功crtPath=',
crtPath,
',keyPath=',
keyPath
);
}
} finally {
//删除临时文件
this.logger.info('删除临时文件');
fs.unlinkSync(saveCrtPath);
fs.unlinkSync(saveKeyPath);
}
this.logger.info('执行完成');
//输出
this.hostCrtPath = crtPath;
this.hostKeyPath = keyPath;