mirror of
https://github.com/certd/certd.git
synced 2026-04-14 12:30:54 +08:00
chore:
This commit is contained in:
@@ -34,6 +34,15 @@ export class CopyCertToLocalPlugin extends AbstractTaskPlugin {
|
||||
})
|
||||
keyPath!: string;
|
||||
|
||||
@TaskInput({
|
||||
title: '中间证书保存路径',
|
||||
helper: '需要有写入权限,路径要包含私钥文件名,文件名不能用*?!等特殊符号,例如:/tmp/intermediate.crt',
|
||||
component: {
|
||||
placeholder: '/root/deploy/nginx/intermediate.crt',
|
||||
},
|
||||
})
|
||||
icPath!: string;
|
||||
|
||||
@TaskInput({
|
||||
title: 'PFX证书保存路径',
|
||||
helper: '用于IIS证书部署,路径要包含文件名,文件名不能用*?!等特殊符号\n推荐使用相对路径,将写入与数据库同级目录,无需映射,例如:./tmp/cert.pfx',
|
||||
@@ -76,6 +85,12 @@ export class CopyCertToLocalPlugin extends AbstractTaskPlugin {
|
||||
})
|
||||
hostKeyPath!: string;
|
||||
|
||||
@TaskOutput({
|
||||
title: '中间证书保存路径',
|
||||
type: 'HostKeyPath',
|
||||
})
|
||||
hostIcPath!: string;
|
||||
|
||||
@TaskOutput({
|
||||
title: 'PFX保存路径',
|
||||
type: 'HostPfxPath',
|
||||
@@ -99,7 +114,7 @@ export class CopyCertToLocalPlugin extends AbstractTaskPlugin {
|
||||
fs.copyFileSync(srcFile, destFile);
|
||||
}
|
||||
async execute(): Promise<void> {
|
||||
let { crtPath, keyPath, pfxPath, derPath } = this;
|
||||
let { crtPath, keyPath, icPath, pfxPath, derPath } = this;
|
||||
const certReader = new CertReader(this.cert);
|
||||
|
||||
const handle = async ({ reader, tmpCrtPath, tmpKeyPath, tmpDerPath, tmpPfxPath }) => {
|
||||
@@ -114,6 +129,11 @@ export class CopyCertToLocalPlugin extends AbstractTaskPlugin {
|
||||
this.copyFile(tmpKeyPath, keyPath);
|
||||
this.hostKeyPath = keyPath;
|
||||
}
|
||||
if (icPath) {
|
||||
icPath = icPath.startsWith('/') ? icPath : path.join(Constants.dataDir, icPath);
|
||||
this.copyFile(tmpPfxPath, icPath);
|
||||
this.hostIcPath = icPath;
|
||||
}
|
||||
if (pfxPath) {
|
||||
pfxPath = pfxPath.startsWith('/') ? pfxPath : path.join(Constants.dataDir, pfxPath);
|
||||
this.copyFile(tmpPfxPath, pfxPath);
|
||||
|
||||
@@ -79,7 +79,7 @@ export class UploadCertToHostPlugin extends AbstractTaskPlugin {
|
||||
name: 'pi-access-selector',
|
||||
type: 'ssh',
|
||||
},
|
||||
rules: [{ required: false, message: '' }],
|
||||
required: true,
|
||||
})
|
||||
accessId!: string;
|
||||
|
||||
@@ -106,18 +106,6 @@ export class UploadCertToHostPlugin extends AbstractTaskPlugin {
|
||||
})
|
||||
script!: string;
|
||||
|
||||
@TaskInput({
|
||||
title: '仅复制到当前主机',
|
||||
helper:
|
||||
'注意:本配置即将废弃\n' +
|
||||
'开启后,将直接复制到当前主机某个目录,不上传到主机,由于是docker启动,实际上是复制到docker容器内的“证书保存路径”\n' +
|
||||
'你需要事先在docker-compose.yaml中配置主机目录映射: volumes: /your_target_path:/your_target_path',
|
||||
value: false,
|
||||
component: {
|
||||
name: 'a-switch',
|
||||
vModel: 'checked',
|
||||
},
|
||||
})
|
||||
copyToThisHost!: boolean;
|
||||
|
||||
@TaskOutput({
|
||||
@@ -168,68 +156,70 @@ export class UploadCertToHostPlugin extends AbstractTaskPlugin {
|
||||
const { tmpCrtPath, tmpKeyPath, tmpDerPath, tmpPfxPath, tmpIcPath } = opts;
|
||||
if (this.copyToThisHost) {
|
||||
this.logger.info('复制到目标路径');
|
||||
this.copyFile(tmpCrtPath, crtPath);
|
||||
this.copyFile(tmpKeyPath, keyPath);
|
||||
this.copyFile(tmpIcPath, this.icPath);
|
||||
this.copyFile(tmpPfxPath, this.pfxPath);
|
||||
this.copyFile(tmpDerPath, this.derPath);
|
||||
} else {
|
||||
if (!accessId) {
|
||||
throw new Error('主机登录授权配置不能为空');
|
||||
}
|
||||
this.logger.info('准备上传文件到服务器');
|
||||
|
||||
const transports: any = [];
|
||||
if (crtPath) {
|
||||
transports.push({
|
||||
localPath: tmpCrtPath,
|
||||
remotePath: crtPath,
|
||||
});
|
||||
this.logger.info(`上传证书到主机:${crtPath}`);
|
||||
}
|
||||
if (keyPath) {
|
||||
transports.push({
|
||||
localPath: tmpKeyPath,
|
||||
remotePath: keyPath,
|
||||
});
|
||||
this.logger.info(`上传私钥到主机:${keyPath}`);
|
||||
}
|
||||
if (this.icPath) {
|
||||
transports.push({
|
||||
localPath: tmpIcPath,
|
||||
remotePath: this.icPath,
|
||||
});
|
||||
this.logger.info(`上传中间证书到主机:${this.icPath}`);
|
||||
}
|
||||
if (this.pfxPath) {
|
||||
transports.push({
|
||||
localPath: tmpPfxPath,
|
||||
remotePath: this.pfxPath,
|
||||
});
|
||||
this.logger.info(`上传PFX证书到主机:${this.pfxPath}`);
|
||||
}
|
||||
if (this.derPath) {
|
||||
transports.push({
|
||||
localPath: tmpDerPath,
|
||||
remotePath: this.derPath,
|
||||
});
|
||||
this.logger.info(`上传DER证书到主机:${this.derPath}`);
|
||||
}
|
||||
this.logger.info('开始上传文件到服务器');
|
||||
await sshClient.uploadFiles({
|
||||
connectConf,
|
||||
transports,
|
||||
mkdirs: this.mkdirs,
|
||||
});
|
||||
this.logger.info('上传文件到服务器成功');
|
||||
//输出
|
||||
this.hostCrtPath = crtPath;
|
||||
this.hostKeyPath = keyPath;
|
||||
this.hostIcPath = this.icPath;
|
||||
this.hostPfxPath = this.pfxPath;
|
||||
this.hostDerPath = this.derPath;
|
||||
throw new Error('复制到当前主机功能已迁移到 “复制到本机”插件');
|
||||
// this.copyFile(tmpCrtPath, crtPath);
|
||||
// this.copyFile(tmpKeyPath, keyPath);
|
||||
// this.copyFile(tmpIcPath, this.icPath);
|
||||
// this.copyFile(tmpPfxPath, this.pfxPath);
|
||||
// this.copyFile(tmpDerPath, this.derPath);
|
||||
}
|
||||
|
||||
if (!accessId) {
|
||||
throw new Error('主机登录授权配置不能为空');
|
||||
}
|
||||
this.logger.info('准备上传文件到服务器');
|
||||
|
||||
const transports: any = [];
|
||||
if (crtPath) {
|
||||
transports.push({
|
||||
localPath: tmpCrtPath,
|
||||
remotePath: crtPath,
|
||||
});
|
||||
this.logger.info(`上传证书到主机:${crtPath}`);
|
||||
}
|
||||
if (keyPath) {
|
||||
transports.push({
|
||||
localPath: tmpKeyPath,
|
||||
remotePath: keyPath,
|
||||
});
|
||||
this.logger.info(`上传私钥到主机:${keyPath}`);
|
||||
}
|
||||
if (this.icPath) {
|
||||
transports.push({
|
||||
localPath: tmpIcPath,
|
||||
remotePath: this.icPath,
|
||||
});
|
||||
this.logger.info(`上传中间证书到主机:${this.icPath}`);
|
||||
}
|
||||
if (this.pfxPath) {
|
||||
transports.push({
|
||||
localPath: tmpPfxPath,
|
||||
remotePath: this.pfxPath,
|
||||
});
|
||||
this.logger.info(`上传PFX证书到主机:${this.pfxPath}`);
|
||||
}
|
||||
if (this.derPath) {
|
||||
transports.push({
|
||||
localPath: tmpDerPath,
|
||||
remotePath: this.derPath,
|
||||
});
|
||||
this.logger.info(`上传DER证书到主机:${this.derPath}`);
|
||||
}
|
||||
this.logger.info('开始上传文件到服务器');
|
||||
await sshClient.uploadFiles({
|
||||
connectConf,
|
||||
transports,
|
||||
mkdirs: this.mkdirs,
|
||||
});
|
||||
this.logger.info('上传文件到服务器成功');
|
||||
//输出
|
||||
this.hostCrtPath = crtPath;
|
||||
this.hostKeyPath = keyPath;
|
||||
this.hostIcPath = this.icPath;
|
||||
this.hostPfxPath = this.pfxPath;
|
||||
this.hostDerPath = this.derPath;
|
||||
};
|
||||
|
||||
await certReader.readCertFile({
|
||||
logger: this.logger,
|
||||
handle,
|
||||
|
||||
Reference in New Issue
Block a user