mirror of
https://github.com/certd/certd.git
synced 2026-04-23 11:37:23 +08:00
chore: 1
This commit is contained in:
@@ -19,18 +19,18 @@ import path from 'path';
|
||||
export class CopyCertToLocalPlugin extends AbstractTaskPlugin {
|
||||
@TaskInput({
|
||||
title: '证书保存路径',
|
||||
helper: '全链证书,路径要包含文件名' + '\n推荐使用相对路径,将写入与数据库同级目录,无需映射,例如:./tmp/cert.pem',
|
||||
helper: '全链证书,路径要包含文件名' + '\n推荐使用相对路径,将写入与数据库同级目录,无需映射,例如:tmp/cert.pem',
|
||||
component: {
|
||||
placeholder: './tmp/full_chain.pem',
|
||||
placeholder: 'tmp/full_chain.pem',
|
||||
},
|
||||
rules: [{ type: 'filepath' }],
|
||||
})
|
||||
crtPath!: string;
|
||||
@TaskInput({
|
||||
title: '私钥保存路径',
|
||||
helper: '路径要包含文件名\n推荐使用相对路径,将写入与数据库同级目录,无需映射,例如:./tmp/cert.key',
|
||||
helper: '路径要包含文件名\n推荐使用相对路径,将写入与数据库同级目录,无需映射,例如:tmp/cert.key',
|
||||
component: {
|
||||
placeholder: './tmp/cert.key',
|
||||
placeholder: 'tmp/cert.key',
|
||||
},
|
||||
rules: [{ type: 'filepath' }],
|
||||
})
|
||||
@@ -48,9 +48,9 @@ export class CopyCertToLocalPlugin extends AbstractTaskPlugin {
|
||||
|
||||
@TaskInput({
|
||||
title: 'PFX证书保存路径',
|
||||
helper: '用于IIS证书部署,路径要包含文件名\n推荐使用相对路径,将写入与数据库同级目录,无需映射,例如:./tmp/cert.pfx',
|
||||
helper: '用于IIS证书部署,路径要包含文件名\n推荐使用相对路径,将写入与数据库同级目录,无需映射,例如:tmp/cert.pfx',
|
||||
component: {
|
||||
placeholder: './tmp/cert.pfx',
|
||||
placeholder: 'tmp/cert.pfx',
|
||||
},
|
||||
rules: [{ type: 'filepath' }],
|
||||
})
|
||||
@@ -59,14 +59,24 @@ export class CopyCertToLocalPlugin extends AbstractTaskPlugin {
|
||||
@TaskInput({
|
||||
title: 'DER证书保存路径',
|
||||
helper:
|
||||
'用于Apache证书部署,路径要包含文件名\n推荐使用相对路径,将写入与数据库同级目录,无需映射,例如:./tmp/cert.der\n.der和.cer是相同的东西,改个后缀名即可',
|
||||
'用于Apache证书部署,路径要包含文件名\n推荐使用相对路径,将写入与数据库同级目录,无需映射,例如:tmp/cert.der\n.der和.cer是相同的东西,改个后缀名即可',
|
||||
component: {
|
||||
placeholder: './tmp/cert.der 或 ./tmp/cert.cer',
|
||||
placeholder: 'tmp/cert.der 或 tmp/cert.cer',
|
||||
},
|
||||
rules: [{ type: 'filepath' }],
|
||||
})
|
||||
derPath!: string;
|
||||
|
||||
@TaskInput({
|
||||
title: 'p12证书保存路径',
|
||||
helper: '用于java,路径要包含文件名,例如:tmp/cert.p12',
|
||||
component: {
|
||||
placeholder: 'tmp/cert.p12',
|
||||
},
|
||||
rules: [{ type: 'filepath' }],
|
||||
})
|
||||
p12Path!: string;
|
||||
|
||||
@TaskInput({
|
||||
title: '域名证书',
|
||||
helper: '请选择前置任务输出的域名证书',
|
||||
@@ -108,6 +118,12 @@ export class CopyCertToLocalPlugin extends AbstractTaskPlugin {
|
||||
})
|
||||
hostDerPath!: string;
|
||||
|
||||
@TaskOutput({
|
||||
title: 'P12保存路径',
|
||||
type: 'HostP12Path',
|
||||
})
|
||||
hostP12Path!: string;
|
||||
|
||||
async onInstance() {}
|
||||
|
||||
copyFile(srcFile: string, destFile: string) {
|
||||
@@ -123,10 +139,10 @@ export class CopyCertToLocalPlugin extends AbstractTaskPlugin {
|
||||
throw new Error('只有管理员才能运行此任务');
|
||||
}
|
||||
|
||||
let { crtPath, keyPath, icPath, pfxPath, derPath } = this;
|
||||
let { crtPath, keyPath, icPath, pfxPath, derPath, p12Path } = this;
|
||||
const certReader = new CertReader(this.cert);
|
||||
|
||||
const handle = async ({ reader, tmpCrtPath, tmpKeyPath, tmpDerPath, tmpPfxPath, tmpIcPath }) => {
|
||||
const handle = async ({ reader, tmpCrtPath, tmpKeyPath, tmpDerPath, tmpPfxPath, tmpIcPath, tmpP12Path }) => {
|
||||
this.logger.info('复制到目标路径');
|
||||
if (crtPath) {
|
||||
crtPath = crtPath.startsWith('/') ? crtPath : path.join(Constants.dataDir, crtPath);
|
||||
@@ -153,6 +169,11 @@ export class CopyCertToLocalPlugin extends AbstractTaskPlugin {
|
||||
this.copyFile(tmpDerPath, derPath);
|
||||
this.hostDerPath = derPath;
|
||||
}
|
||||
if (p12Path) {
|
||||
p12Path = p12Path.startsWith('/') ? p12Path : path.join(Constants.dataDir, p12Path);
|
||||
this.copyFile(tmpP12Path, p12Path);
|
||||
this.hostP12Path = p12Path;
|
||||
}
|
||||
this.logger.info('请注意,如果使用的是相对路径,那么文件就在你的数据库同级目录下,默认是/data/certd/下面');
|
||||
this.logger.info(
|
||||
'请注意,如果使用的是绝对路径,文件在容器内的目录下,你需要给容器做目录映射才能复制到宿主机,需要在docker-compose.yaml中配置主机目录映射: volumes: /你宿主机的路径:/任务配置的证书路径'
|
||||
|
||||
@@ -67,6 +67,16 @@ export class UploadCertToHostPlugin extends AbstractTaskPlugin {
|
||||
})
|
||||
derPath!: string;
|
||||
|
||||
@TaskInput({
|
||||
title: 'p12证书保存路径',
|
||||
helper: '需要有写入权限,路径要包含证书文件名,例如:/tmp/cert.p12',
|
||||
component: {
|
||||
placeholder: '/root/deploy/nginx/cert.p12',
|
||||
},
|
||||
rules: [{ type: 'filepath' }],
|
||||
})
|
||||
p12Path!: string;
|
||||
|
||||
@TaskInput({
|
||||
title: '域名证书',
|
||||
helper: '请选择前置任务输出的域名证书',
|
||||
@@ -147,6 +157,10 @@ export class UploadCertToHostPlugin extends AbstractTaskPlugin {
|
||||
title: 'DER保存路径',
|
||||
})
|
||||
hostDerPath!: string;
|
||||
@TaskOutput({
|
||||
title: 'P12保存路径',
|
||||
})
|
||||
hostP12Path!: string;
|
||||
|
||||
async onInstance() {}
|
||||
|
||||
@@ -167,7 +181,7 @@ export class UploadCertToHostPlugin extends AbstractTaskPlugin {
|
||||
const certReader = new CertReader(cert);
|
||||
|
||||
const handle = async (opts: CertReaderHandleContext) => {
|
||||
const { tmpCrtPath, tmpKeyPath, tmpDerPath, tmpPfxPath, tmpIcPath } = opts;
|
||||
const { tmpCrtPath, tmpKeyPath, tmpDerPath, tmpP12Path, tmpPfxPath, tmpIcPath } = opts;
|
||||
// if (this.copyToThisHost) {
|
||||
// this.logger.info('复制到目标路径');
|
||||
// this.copyFile(tmpCrtPath, crtPath);
|
||||
@@ -227,6 +241,13 @@ export class UploadCertToHostPlugin extends AbstractTaskPlugin {
|
||||
});
|
||||
this.logger.info(`上传DER证书到主机:${this.derPath}`);
|
||||
}
|
||||
if (this.p12Path) {
|
||||
transports.push({
|
||||
localPath: tmpP12Path,
|
||||
remotePath: this.p12Path,
|
||||
});
|
||||
this.logger.info(`上传p12证书到主机:${this.p12Path}`);
|
||||
}
|
||||
this.logger.info('开始上传文件到服务器');
|
||||
await sshClient.uploadFiles({
|
||||
connectConf,
|
||||
@@ -240,6 +261,7 @@ export class UploadCertToHostPlugin extends AbstractTaskPlugin {
|
||||
this.hostIcPath = this.icPath;
|
||||
this.hostPfxPath = this.pfxPath;
|
||||
this.hostDerPath = this.derPath;
|
||||
this.hostP12Path = this.p12Path;
|
||||
};
|
||||
|
||||
await certReader.readCertFile({
|
||||
|
||||
Reference in New Issue
Block a user