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