chore: format

This commit is contained in:
xiaojunnuo
2026-05-31 01:41:33 +08:00
parent acd440106b
commit 4b57a0d729
557 changed files with 12530 additions and 14039 deletions
@@ -1,14 +1,14 @@
import { AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput, TaskOutput } from '@certd/pipeline';
import { CertInfo, CertReader } from '@certd/plugin-cert';
import * as fs from 'fs';
import path from 'path';
import { CertApplyPluginNames} from '@certd/plugin-cert';
const dataDir = "./data"
import { AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput, TaskOutput } from "@certd/pipeline";
import { CertInfo, CertReader } from "@certd/plugin-cert";
import * as fs from "fs";
import path from "path";
import { CertApplyPluginNames } from "@certd/plugin-cert";
const dataDir = "./data";
@IsTaskPlugin({
name: 'CopyToLocal',
title: '主机-复制到本机',
icon: 'solar:copy-bold-duotone',
desc: '【仅管理员使用】实际上是复制证书到docker容器内的某个路径,需要做目录映射到宿主机',
name: "CopyToLocal",
title: "主机-复制到本机",
icon: "solar:copy-bold-duotone",
desc: "【仅管理员使用】实际上是复制证书到docker容器内的某个路径,需要做目录映射到宿主机",
group: pluginGroups.host.key,
default: {
strategy: {
@@ -18,10 +18,10 @@ const dataDir = "./data"
})
export class CopyCertToLocalPlugin extends AbstractTaskPlugin {
@TaskInput({
title: '域名证书',
helper: '请选择前置任务输出的域名证书',
title: "域名证书",
helper: "请选择前置任务输出的域名证书",
component: {
name: 'output-selector',
name: "output-selector",
from: [...CertApplyPluginNames],
},
required: true,
@@ -29,15 +29,15 @@ export class CopyCertToLocalPlugin extends AbstractTaskPlugin {
cert!: CertInfo;
@TaskInput({
title: '证书类型',
helper: '要部署的证书格式,支持pem、pfx、der、jks格式',
title: "证书类型",
helper: "要部署的证书格式,支持pem、pfx、der、jks格式",
component: {
name: 'a-select',
name: "a-select",
options: [
{ value: 'pem', label: 'pem(crt),用于Nginx等大部分应用' },
{ value: 'pfx', label: 'pfx,一般用于IIS' },
{ value: 'der', label: 'der,一般用于Apache' },
{ value: 'jks', label: 'jks,一般用于JAVA应用' },
{ value: "pem", label: "pem(crt),用于Nginx等大部分应用" },
{ value: "pfx", label: "pfx,一般用于IIS" },
{ value: "der", label: "der,一般用于Apache" },
{ value: "jks", label: "jks,一般用于JAVA应用" },
],
},
required: true,
@@ -45,10 +45,10 @@ export class CopyCertToLocalPlugin extends AbstractTaskPlugin {
certType!: string;
@TaskInput({
title: '证书保存路径',
helper: '全链证书,路径要包含文件名' + '\n推荐使用相对路径,将写入与数据库同级目录,无需映射,例如:tmp/cert.pem',
title: "证书保存路径",
helper: "全链证书,路径要包含文件名" + "\n推荐使用相对路径,将写入与数据库同级目录,无需映射,例如:tmp/cert.pem",
component: {
placeholder: 'tmp/full_chain.pem',
placeholder: "tmp/full_chain.pem",
},
mergeScript: `
return {
@@ -58,14 +58,14 @@ export class CopyCertToLocalPlugin extends AbstractTaskPlugin {
}
`,
required: true,
rules: [{ type: 'filepath' }],
rules: [{ type: "filepath" }],
})
crtPath!: string;
@TaskInput({
title: '私钥保存路径',
helper: '路径要包含文件名\n推荐使用相对路径,将写入与数据库同级目录,无需映射,例如:tmp/cert.key',
title: "私钥保存路径",
helper: "路径要包含文件名\n推荐使用相对路径,将写入与数据库同级目录,无需映射,例如:tmp/cert.key",
component: {
placeholder: 'tmp/cert.key',
placeholder: "tmp/cert.key",
},
mergeScript: `
return {
@@ -75,15 +75,15 @@ export class CopyCertToLocalPlugin extends AbstractTaskPlugin {
}
`,
required: true,
rules: [{ type: 'filepath' }],
rules: [{ type: "filepath" }],
})
keyPath!: string;
@TaskInput({
title: '中间证书保存路径',
helper: '路径要包含文件名,一般情况传上面两个文件就行了,极少数情况需要这个中间证书',
title: "中间证书保存路径",
helper: "路径要包含文件名,一般情况传上面两个文件就行了,极少数情况需要这个中间证书",
component: {
placeholder: '/root/deploy/nginx/intermediate.pem',
placeholder: "/root/deploy/nginx/intermediate.pem",
},
mergeScript: `
return {
@@ -92,15 +92,15 @@ export class CopyCertToLocalPlugin extends AbstractTaskPlugin {
})
}
`,
rules: [{ type: 'filepath' }],
rules: [{ type: "filepath" }],
})
icPath!: string;
@TaskInput({
title: 'PFX证书保存路径',
helper: '用于IIS证书部署,路径要包含文件名\n推荐使用相对路径,将写入与数据库同级目录,无需映射,例如:tmp/cert.pfx',
title: "PFX证书保存路径",
helper: "用于IIS证书部署,路径要包含文件名\n推荐使用相对路径,将写入与数据库同级目录,无需映射,例如:tmp/cert.pfx",
component: {
placeholder: 'tmp/cert.pfx',
placeholder: "tmp/cert.pfx",
},
mergeScript: `
return {
@@ -110,16 +110,15 @@ export class CopyCertToLocalPlugin extends AbstractTaskPlugin {
}
`,
required: true,
rules: [{ type: 'filepath' }],
rules: [{ type: "filepath" }],
})
pfxPath!: string;
@TaskInput({
title: 'DER证书保存路径',
helper:
'用于Apache证书部署,路径要包含文件名\n推荐使用相对路径,将写入与数据库同级目录,无需映射,例如:tmp/cert.der\n.der和.cer是相同的东西,改个后缀名即可',
title: "DER证书保存路径",
helper: "用于Apache证书部署,路径要包含文件名\n推荐使用相对路径,将写入与数据库同级目录,无需映射,例如:tmp/cert.der\n.der和.cer是相同的东西,改个后缀名即可",
component: {
placeholder: 'tmp/cert.der 或 tmp/cert.cer',
placeholder: "tmp/cert.der 或 tmp/cert.cer",
},
mergeScript: `
return {
@@ -129,15 +128,15 @@ export class CopyCertToLocalPlugin extends AbstractTaskPlugin {
}
`,
required: true,
rules: [{ type: 'filepath' }],
rules: [{ type: "filepath" }],
})
derPath!: string;
@TaskInput({
title: 'jks证书保存路径',
helper: '用于java,路径要包含文件名,例如:tmp/cert.jks',
title: "jks证书保存路径",
helper: "用于java,路径要包含文件名,例如:tmp/cert.jks",
component: {
placeholder: 'tmp/cert.jks',
placeholder: "tmp/cert.jks",
},
mergeScript: `
return {
@@ -147,43 +146,43 @@ export class CopyCertToLocalPlugin extends AbstractTaskPlugin {
}
`,
required: true,
rules: [{ type: 'filepath' }],
rules: [{ type: "filepath" }],
})
jksPath!: string;
@TaskOutput({
title: '证书保存路径',
type: 'HostCrtPath',
title: "证书保存路径",
type: "HostCrtPath",
})
hostCrtPath!: string;
@TaskOutput({
title: '私钥保存路径',
type: 'HostKeyPath',
title: "私钥保存路径",
type: "HostKeyPath",
})
hostKeyPath!: string;
@TaskOutput({
title: '中间证书保存路径',
type: 'HostKeyPath',
title: "中间证书保存路径",
type: "HostKeyPath",
})
hostIcPath!: string;
@TaskOutput({
title: 'PFX保存路径',
type: 'HostPfxPath',
title: "PFX保存路径",
type: "HostPfxPath",
})
hostPfxPath!: string;
@TaskOutput({
title: 'DER保存路径',
type: 'HostDerPath',
title: "DER保存路径",
type: "HostDerPath",
})
hostDerPath!: string;
@TaskOutput({
title: 'jks保存路径',
type: 'HostJksPath',
title: "jks保存路径",
type: "HostJksPath",
})
hostJksPath!: string;
@@ -204,52 +203,50 @@ export class CopyCertToLocalPlugin extends AbstractTaskPlugin {
const certReader = new CertReader(this.cert);
const handle = async ({ reader, tmpCrtPath, tmpKeyPath, tmpDerPath, tmpPfxPath, tmpIcPath, tmpJksPath }) => {
this.logger.info('复制到目标路径');
this.logger.info("复制到目标路径");
if (crtPath) {
crtPath = crtPath.trim();
crtPath = crtPath.startsWith('/') ? crtPath : path.join(dataDir, crtPath);
crtPath = crtPath.startsWith("/") ? crtPath : path.join(dataDir, crtPath);
this.copyFile(tmpCrtPath, crtPath);
this.hostCrtPath = crtPath;
}
if (keyPath) {
keyPath = keyPath.trim();
keyPath = keyPath.startsWith('/') ? keyPath : path.join(dataDir, keyPath);
keyPath = keyPath.startsWith("/") ? keyPath : path.join(dataDir, keyPath);
this.copyFile(tmpKeyPath, keyPath);
this.hostKeyPath = keyPath;
}
if (icPath) {
icPath = icPath.trim();
icPath = icPath.startsWith('/') ? icPath : path.join(dataDir, icPath);
icPath = icPath.startsWith("/") ? icPath : path.join(dataDir, icPath);
this.copyFile(tmpIcPath, icPath);
this.hostIcPath = icPath;
}
if (pfxPath) {
pfxPath = pfxPath.trim();
pfxPath = pfxPath.startsWith('/') ? pfxPath : path.join(dataDir, pfxPath);
pfxPath = pfxPath.startsWith("/") ? pfxPath : path.join(dataDir, pfxPath);
this.copyFile(tmpPfxPath, pfxPath);
this.hostPfxPath = pfxPath;
}
if (derPath) {
derPath = derPath.trim();
derPath = derPath.startsWith('/') ? derPath : path.join(dataDir, derPath);
derPath = derPath.startsWith("/") ? derPath : path.join(dataDir, derPath);
this.copyFile(tmpDerPath, derPath);
this.hostDerPath = derPath;
}
if (jksPath) {
jksPath = jksPath.trim();
jksPath = jksPath.startsWith('/') ? jksPath : path.join(dataDir, jksPath);
jksPath = jksPath.startsWith("/") ? jksPath : path.join(dataDir, jksPath);
this.copyFile(tmpJksPath, jksPath);
this.hostJksPath = jksPath;
}
this.logger.info('请注意,如果使用的是相对路径,那么文件就在你的数据库同级目录下,默认是/data/certd/下面');
this.logger.info(
'请注意,如果使用的是绝对路径,文件在容器内的目录下,你需要给容器做目录映射才能复制到宿主机,需要在docker-compose.yaml中配置主机目录映射: volumes: /你宿主机的路径:/任务配置的证书路径'
);
this.logger.info("请注意,如果使用的是相对路径,那么文件就在你的数据库同级目录下,默认是/data/certd/下面");
this.logger.info("请注意,如果使用的是绝对路径,文件在容器内的目录下,你需要给容器做目录映射才能复制到宿主机,需要在docker-compose.yaml中配置主机目录映射: volumes: /你宿主机的路径:/任务配置的证书路径");
};
await certReader.readCertFile({ logger: this.logger, handle });
this.logger.info('执行完成');
this.logger.info("执行完成");
}
}
@@ -1,11 +1,11 @@
import { AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput } from '@certd/pipeline';
import { SshClient } from '../../../plugin-lib/ssh/index.js';
import { AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput } from "@certd/pipeline";
import { SshClient } from "../../../plugin-lib/ssh/index.js";
@IsTaskPlugin({
name: 'hostShellExecute',
title: '主机-执行远程主机脚本命令',
icon: 'tabler:brand-powershell',
name: "hostShellExecute",
title: "主机-执行远程主机脚本命令",
icon: "tabler:brand-powershell",
group: pluginGroups.host.key,
desc: '可以执行重启nginx等操作让证书生效',
desc: "可以执行重启nginx等操作让证书生效",
input: {},
showRunStrategy: true,
default: {
@@ -17,24 +17,24 @@ import { SshClient } from '../../../plugin-lib/ssh/index.js';
})
export class HostShellExecutePlugin extends AbstractTaskPlugin {
@TaskInput({
title: '主机登录配置',
helper: '登录',
title: "主机登录配置",
helper: "登录",
component: {
name: 'access-selector',
type: 'ssh',
name: "access-selector",
type: "ssh",
},
required: true,
})
accessId!: string;
@TaskInput({
title: 'shell脚本命令',
title: "shell脚本命令",
component: {
name: 'a-textarea',
vModel: 'value',
name: "a-textarea",
vModel: "value",
rows: 6,
placeholder: 'systemctl restart nginx',
placeholder: "systemctl restart nginx",
},
helper: '注意:如果目标主机是windows,且终端是cmd,系统会自动将多行命令通过“&&”连接成一行',
helper: "注意:如果目标主机是windows,且终端是cmd,系统会自动将多行命令通过“&&”连接成一行",
required: true,
})
script!: string;
@@ -45,7 +45,7 @@ export class HostShellExecutePlugin extends AbstractTaskPlugin {
const connectConf = await this.getAccess(accessId);
const sshClient = new SshClient(this.logger);
const scripts = script.split('\n');
const scripts = script.split("\n");
await sshClient.exec({
connectConf,
script: scripts,
@@ -1,5 +1,5 @@
export * from './host-shell-execute/index.js';
export * from './upload-to-host/index.js';
export * from './copy-to-local/index.js'
export * from './plugin-upload-to-oss.js'
export * from './plugin-deploy-to-iis.js'
export * from "./host-shell-execute/index.js";
export * from "./upload-to-host/index.js";
export * from "./copy-to-local/index.js";
export * from "./plugin-upload-to-oss.js";
export * from "./plugin-deploy-to-iis.js";
@@ -1,15 +1,15 @@
import {AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput} from '@certd/pipeline';
import {CertInfo} from "@certd/plugin-cert";
import {utils} from "@certd/basic";
import { ossClientFactory } from '../../plugin-lib/oss/factory.js';
import { AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput } from "@certd/pipeline";
import { CertInfo } from "@certd/plugin-cert";
import { utils } from "@certd/basic";
import { ossClientFactory } from "../../plugin-lib/oss/factory.js";
@IsTaskPlugin({
name: 'UploadCertToOss',
title: '上传证书到对象存储OSS',
icon: 'ion:cloud-upload-outline',
desc: '支持阿里云OSS、腾讯云COS、七牛云KODO、S3、MinIO、FTP、SFTP',
name: "UploadCertToOss",
title: "上传证书到对象存储OSS",
icon: "ion:cloud-upload-outline",
desc: "支持阿里云OSS、腾讯云COS、七牛云KODO、S3、MinIO、FTP、SFTP",
group: pluginGroups.host.key,
showRunStrategy:false,
showRunStrategy: false,
default: {
strategy: {
runStrategy: RunStrategy.SkipWhenSucceed,
@@ -17,24 +17,22 @@ import { ossClientFactory } from '../../plugin-lib/oss/factory.js';
},
})
export class UploadCertToOssPlugin extends AbstractTaskPlugin {
@TaskInput({
title: '域名证书',
helper: '请选择前置任务输出的域名证书',
title: "域名证书",
helper: "请选择前置任务输出的域名证书",
component: {
name: 'output-selector',
name: "output-selector",
from: [":cert:"],
},
required: true,
})
cert!: CertInfo;
@TaskInput({
title: 'OSS类型',
title: "OSS类型",
component: {
name: 'a-select',
vModel:"value",
name: "a-select",
vModel: "value",
options: [
{ label: "阿里云OSS", value: "alioss" },
{ label: "腾讯云COS", value: "tencentcos" },
@@ -42,17 +40,16 @@ export class UploadCertToOssPlugin extends AbstractTaskPlugin {
{ label: "S3/Minio", value: "s3" },
{ label: "SFTP", value: "sftp" },
{ label: "FTP", value: "ftp" },
]
],
},
required: true,
})
uploaderType!: string;
@TaskInput({
title: 'OSS授权',
title: "OSS授权",
component: {
name: 'access-selector',
name: "access-selector",
},
required: true,
mergeScript: `
@@ -67,18 +64,17 @@ export class UploadCertToOssPlugin extends AbstractTaskPlugin {
})
accessId!: string;
@TaskInput({
title: '证书格式',
helper: '要部署的证书格式,支持pem、pfx、der、jks',
title: "证书格式",
helper: "要部署的证书格式,支持pem、pfx、der、jks",
component: {
name: 'a-select',
name: "a-select",
options: [
{ value: 'pem', label: 'pemcrt),Nginx等大部分应用' },
{ value: 'pfx', label: 'pfx,一般用于IIS' },
{ value: 'der', label: 'der,一般用于Apache' },
{ value: 'jks', label: 'jks,一般用于JAVA应用' },
{ value: 'one', label: '证书私钥一体,crt+key简单合并为一个pem文件' },
{ value: "pem", label: "pemcrt),Nginx等大部分应用" },
{ value: "pfx", label: "pfx,一般用于IIS" },
{ value: "der", label: "der,一般用于Apache" },
{ value: "jks", label: "jks,一般用于JAVA应用" },
{ value: "one", label: "证书私钥一体,crt+key简单合并为一个pem文件" },
],
},
required: true,
@@ -86,10 +82,10 @@ export class UploadCertToOssPlugin extends AbstractTaskPlugin {
certType!: string;
@TaskInput({
title: '证书保存路径',
helper: '路径要包含证书文件名,例如:/tmp/cert.pem',
title: "证书保存路径",
helper: "路径要包含证书文件名,例如:/tmp/cert.pem",
component: {
placeholder: '/root/deploy/nginx/full_chain.pem',
placeholder: "/root/deploy/nginx/full_chain.pem",
},
mergeScript: `
return {
@@ -99,14 +95,14 @@ export class UploadCertToOssPlugin extends AbstractTaskPlugin {
}
`,
required: true,
rules: [{ type: 'filepath' }],
rules: [{ type: "filepath" }],
})
crtPath!: string;
@TaskInput({
title: '私钥保存路径',
helper: '路径要包含私钥文件名,例如:/tmp/cert.key',
title: "私钥保存路径",
helper: "路径要包含私钥文件名,例如:/tmp/cert.key",
component: {
placeholder: '/root/deploy/nginx/cert.key',
placeholder: "/root/deploy/nginx/cert.key",
},
mergeScript: `
return {
@@ -116,15 +112,15 @@ export class UploadCertToOssPlugin extends AbstractTaskPlugin {
}
`,
required: true,
rules: [{ type: 'filepath' }],
rules: [{ type: "filepath" }],
})
keyPath!: string;
@TaskInput({
title: '中间证书保存路径',
helper: '路径要包含文件名,一般情况传上面两个文件即可,极少数情况需要这个中间证书',
title: "中间证书保存路径",
helper: "路径要包含文件名,一般情况传上面两个文件即可,极少数情况需要这个中间证书",
component: {
placeholder: '/root/deploy/nginx/intermediate.pem',
placeholder: "/root/deploy/nginx/intermediate.pem",
},
mergeScript: `
return {
@@ -133,15 +129,15 @@ export class UploadCertToOssPlugin extends AbstractTaskPlugin {
})
}
`,
rules: [{ type: 'filepath' }],
rules: [{ type: "filepath" }],
})
icPath!: string;
@TaskInput({
title: 'PFX证书保存路径',
helper: '路径要包含证书文件名,例如:D:\\iis\\cert.pfx',
title: "PFX证书保存路径",
helper: "路径要包含证书文件名,例如:D:\\iis\\cert.pfx",
component: {
placeholder: 'D:\\iis\\cert.pfx',
placeholder: "D:\\iis\\cert.pfx",
},
mergeScript: `
return {
@@ -151,15 +147,15 @@ export class UploadCertToOssPlugin extends AbstractTaskPlugin {
}
`,
required: true,
rules: [{ type: 'filepath' }],
rules: [{ type: "filepath" }],
})
pfxPath!: string;
@TaskInput({
title: 'DER证书保存路径',
helper: '路径要包含证书文件名,例如:/tmp/cert.der',
title: "DER证书保存路径",
helper: "路径要包含证书文件名,例如:/tmp/cert.der",
component: {
placeholder: '/root/deploy/apache/cert.der',
placeholder: "/root/deploy/apache/cert.der",
},
mergeScript: `
return {
@@ -169,15 +165,15 @@ export class UploadCertToOssPlugin extends AbstractTaskPlugin {
}
`,
required: true,
rules: [{ type: 'filepath' }],
rules: [{ type: "filepath" }],
})
derPath!: string;
@TaskInput({
title: 'jks证书保存路径',
helper: '路径要包含证书文件名,例如:/tmp/cert.jks',
title: "jks证书保存路径",
helper: "路径要包含证书文件名,例如:/tmp/cert.jks",
component: {
placeholder: '/root/deploy/java_app/cert.jks',
placeholder: "/root/deploy/java_app/cert.jks",
},
mergeScript: `
return {
@@ -187,15 +183,15 @@ export class UploadCertToOssPlugin extends AbstractTaskPlugin {
}
`,
required: true,
rules: [{ type: 'filepath' }],
rules: [{ type: "filepath" }],
})
jksPath!: string;
@TaskInput({
title: '一体证书保存路径',
helper: '路径要包含证书文件名,例如:/tmp/crt_key.pem',
title: "一体证书保存路径",
helper: "路径要包含证书文件名,例如:/tmp/crt_key.pem",
component: {
placeholder: '/app/crt_key.pem',
placeholder: "/app/crt_key.pem",
},
mergeScript: `
return {
@@ -205,21 +201,20 @@ export class UploadCertToOssPlugin extends AbstractTaskPlugin {
}
`,
required: true,
rules: [{ type: 'filepath' }],
rules: [{ type: "filepath" }],
})
onePath!: string;
async onInstance() {}
async execute(): Promise<void> {
const { accessId } = this;
let { crtPath, keyPath, icPath, pfxPath, derPath, jksPath, onePath } = this;
const { crtPath, keyPath, icPath, pfxPath, derPath, jksPath, onePath } = this;
if (!accessId) {
throw new Error('OSS授权配置不能为空');
throw new Error("OSS授权配置不能为空");
}
const uploaderType = this.uploaderType
const uploaderAccess = this.accessId
const uploaderType = this.uploaderType;
const uploaderAccess = this.accessId;
const httpUploaderContext = {
accessService: this.ctx.accessService,
@@ -235,40 +230,39 @@ export class UploadCertToOssPlugin extends AbstractTaskPlugin {
ctx: httpUploaderContext,
});
this.logger.info('准备上传文件到OSS');
this.logger.info("准备上传文件到OSS");
if (crtPath) {
await httpUploader.upload(crtPath, Buffer.from(this.cert.crt))
await httpUploader.upload(crtPath, Buffer.from(this.cert.crt));
this.logger.info(`上传证书:${crtPath}`);
}
if (keyPath) {
await httpUploader.upload(keyPath, Buffer.from(this.cert.key))
await httpUploader.upload(keyPath, Buffer.from(this.cert.key));
this.logger.info(`上传私钥:${keyPath}`);
}
if (icPath) {
await httpUploader.upload(icPath, Buffer.from(this.cert.ic))
await httpUploader.upload(icPath, Buffer.from(this.cert.ic));
this.logger.info(`上传中间证书:${icPath}`);
}
if (pfxPath) {
await httpUploader.upload(pfxPath, Buffer.from(this.cert.pfx, "base64"))
await httpUploader.upload(pfxPath, Buffer.from(this.cert.pfx, "base64"));
this.logger.info(`上传PFX证书:${pfxPath}`);
}
if (derPath) {
await httpUploader.upload(derPath, Buffer.from(this.cert.der, "base64"))
await httpUploader.upload(derPath, Buffer.from(this.cert.der, "base64"));
this.logger.info(`上传DER证书:${derPath}`);
}
if (this.jksPath) {
await httpUploader.upload(jksPath,Buffer.from(this.cert.jks, "base64"))
await httpUploader.upload(jksPath, Buffer.from(this.cert.jks, "base64"));
this.logger.info(`上传jks证书:${jksPath}`);
}
if (onePath) {
await httpUploader.upload(onePath, Buffer.from(this.cert.one))
await httpUploader.upload(onePath, Buffer.from(this.cert.one));
this.logger.info(`上传一体证书:${onePath}`);
}
this.logger.info('上传文件成功');
this.logger.info("上传文件成功");
}
}
new UploadCertToOssPlugin();
@@ -1,14 +1,14 @@
import { AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput, TaskOutput } from '@certd/pipeline';
import { CertInfo, CertReader, CertReaderHandleContext } from '@certd/plugin-cert';
import dayjs from 'dayjs';
import { SshAccess, SshClient } from '../../../plugin-lib/ssh/index.js';
import { CertApplyPluginNames} from '@certd/plugin-cert';
import { AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput, TaskOutput } from "@certd/pipeline";
import { CertInfo, CertReader, CertReaderHandleContext } from "@certd/plugin-cert";
import dayjs from "dayjs";
import { SshAccess, SshClient } from "../../../plugin-lib/ssh/index.js";
import { CertApplyPluginNames } from "@certd/plugin-cert";
@IsTaskPlugin({
name: 'uploadCertToHost',
title: '主机-部署证书到SSH主机',
icon: 'line-md:uploading-loop',
name: "uploadCertToHost",
title: "主机-部署证书到SSH主机",
icon: "line-md:uploading-loop",
group: pluginGroups.host.key,
desc: '上传证书到主机覆盖原来的证书文件,然后自动执行部署脚本命令使证书生效',
desc: "上传证书到主机覆盖原来的证书文件,然后自动执行部署脚本命令使证书生效",
order: 1,
default: {
strategy: {
@@ -18,10 +18,10 @@ import { CertApplyPluginNames} from '@certd/plugin-cert';
})
export class UploadCertToHostPlugin extends AbstractTaskPlugin {
@TaskInput({
title: '域名证书',
helper: '请选择前置任务输出的域名证书',
title: "域名证书",
helper: "请选择前置任务输出的域名证书",
component: {
name: 'output-selector',
name: "output-selector",
from: [...CertApplyPluginNames],
},
required: true,
@@ -29,17 +29,17 @@ export class UploadCertToHostPlugin extends AbstractTaskPlugin {
cert!: CertInfo;
@TaskInput({
title: '证书格式',
helper: '要部署的证书格式,支持pem/crt、pfx、der、jks、p7b\n你原来的证书是哪种格式就选择哪种',
title: "证书格式",
helper: "要部署的证书格式,支持pem/crt、pfx、der、jks、p7b\n你原来的证书是哪种格式就选择哪种",
component: {
name: 'a-select',
name: "a-select",
options: [
{ value: 'pem', label: 'pem/crt,用于Nginx等大部分应用,证书和私钥2个文件' },
{ value: 'pfx', label: 'pfx,一般用于IIS' },
{ value: 'der', label: 'der,一般用于Apache' },
{ value: 'jks', label: 'jks,一般用于JAVA应用' },
{ value: 'one', label: '证书私钥一体,crt+key简单合并为一个pem文件' },
{ value: 'p7b', label: 'p7b格式' },
{ value: "pem", label: "pem/crt,用于Nginx等大部分应用,证书和私钥2个文件" },
{ value: "pfx", label: "pfx,一般用于IIS" },
{ value: "der", label: "der,一般用于Apache" },
{ value: "jks", label: "jks,一般用于JAVA应用" },
{ value: "one", label: "证书私钥一体,crt+key简单合并为一个pem文件" },
{ value: "p7b", label: "p7b格式" },
],
},
required: true,
@@ -47,10 +47,10 @@ export class UploadCertToHostPlugin extends AbstractTaskPlugin {
certType!: string;
@TaskInput({
title: '证书保存路径',
helper: '填写应用原本的证书保存路径,路径要包含证书文件名,例如:/tmp/cert.pem',
title: "证书保存路径",
helper: "填写应用原本的证书保存路径,路径要包含证书文件名,例如:/tmp/cert.pem",
component: {
placeholder: '/root/deploy/nginx/full_chain.pem',
placeholder: "/root/deploy/nginx/full_chain.pem",
},
mergeScript: `
return {
@@ -60,14 +60,14 @@ export class UploadCertToHostPlugin extends AbstractTaskPlugin {
}
`,
required: true,
rules: [{ type: 'filepath' }],
rules: [{ type: "filepath" }],
})
crtPath!: string;
@TaskInput({
title: '私钥保存路径',
helper: '原本的私钥保存路径,需要有写入权限,路径要包含私钥文件名,例如:/tmp/cert.key',
title: "私钥保存路径",
helper: "原本的私钥保存路径,需要有写入权限,路径要包含私钥文件名,例如:/tmp/cert.key",
component: {
placeholder: '/root/deploy/nginx/cert.key',
placeholder: "/root/deploy/nginx/cert.key",
},
mergeScript: `
return {
@@ -77,15 +77,15 @@ export class UploadCertToHostPlugin extends AbstractTaskPlugin {
}
`,
required: true,
rules: [{ type: 'filepath' }],
rules: [{ type: "filepath" }],
})
keyPath!: string;
@TaskInput({
title: '中间证书保存路径',
helper: '路径要包含文件名,一般情况传上面两个文件即可,极少数情况需要这个中间证书',
title: "中间证书保存路径",
helper: "路径要包含文件名,一般情况传上面两个文件即可,极少数情况需要这个中间证书",
component: {
placeholder: '/root/deploy/nginx/intermediate.pem',
placeholder: "/root/deploy/nginx/intermediate.pem",
},
mergeScript: `
return {
@@ -94,15 +94,15 @@ export class UploadCertToHostPlugin extends AbstractTaskPlugin {
})
}
`,
rules: [{ type: 'filepath' }],
rules: [{ type: "filepath" }],
})
icPath!: string;
@TaskInput({
title: 'PFX证书保存路径',
helper: '填写应用原本的证书保存路径,路径要包含证书文件名,例如:D:\\iis\\cert.pfx',
title: "PFX证书保存路径",
helper: "填写应用原本的证书保存路径,路径要包含证书文件名,例如:D:\\iis\\cert.pfx",
component: {
placeholder: 'D:\\iis\\cert.pfx',
placeholder: "D:\\iis\\cert.pfx",
},
mergeScript: `
return {
@@ -112,15 +112,15 @@ export class UploadCertToHostPlugin extends AbstractTaskPlugin {
}
`,
required: true,
rules: [{ type: 'filepath' }],
rules: [{ type: "filepath" }],
})
pfxPath!: string;
@TaskInput({
title: 'DER证书保存路径',
helper: '填写应用原本的证书保存路径,路径要包含证书文件名,例如:/tmp/cert.der',
title: "DER证书保存路径",
helper: "填写应用原本的证书保存路径,路径要包含证书文件名,例如:/tmp/cert.der",
component: {
placeholder: '/root/deploy/apache/cert.der',
placeholder: "/root/deploy/apache/cert.der",
},
mergeScript: `
return {
@@ -130,15 +130,15 @@ export class UploadCertToHostPlugin extends AbstractTaskPlugin {
}
`,
required: true,
rules: [{ type: 'filepath' }],
rules: [{ type: "filepath" }],
})
derPath!: string;
@TaskInput({
title: 'jks证书保存路径',
helper: '填写应用原本的证书保存路径,路径要包含证书文件名,例如:/tmp/cert.jks',
title: "jks证书保存路径",
helper: "填写应用原本的证书保存路径,路径要包含证书文件名,例如:/tmp/cert.jks",
component: {
placeholder: '/root/deploy/java_app/cert.jks',
placeholder: "/root/deploy/java_app/cert.jks",
},
mergeScript: `
return {
@@ -148,15 +148,15 @@ export class UploadCertToHostPlugin extends AbstractTaskPlugin {
}
`,
required: true,
rules: [{ type: 'filepath' }],
rules: [{ type: "filepath" }],
})
jksPath!: string;
@TaskInput({
title: '一体证书保存路径',
helper: '填写应用原本的证书保存路径,路径要包含证书文件名,例如:/tmp/crt_key.pem',
title: "一体证书保存路径",
helper: "填写应用原本的证书保存路径,路径要包含证书文件名,例如:/tmp/crt_key.pem",
component: {
placeholder: '/root/deploy/app/crt_key.pem',
placeholder: "/root/deploy/app/crt_key.pem",
},
mergeScript: `
return {
@@ -166,15 +166,15 @@ export class UploadCertToHostPlugin extends AbstractTaskPlugin {
}
`,
required: true,
rules: [{ type: 'filepath' }],
rules: [{ type: "filepath" }],
})
onePath!: string;
@TaskInput({
title: 'p7b证书保存路径',
helper: '填写应用原本的证书保存路径,路径要包含证书文件名,例如:/tmp/domain_cert.p7b',
title: "p7b证书保存路径",
helper: "填写应用原本的证书保存路径,路径要包含证书文件名,例如:/tmp/domain_cert.p7b",
component: {
placeholder: '/root/deploy/app/domain_cert.p7b',
placeholder: "/root/deploy/app/domain_cert.p7b",
},
mergeScript: `
return {
@@ -184,136 +184,135 @@ export class UploadCertToHostPlugin extends AbstractTaskPlugin {
}
`,
required: true,
rules: [{ type: 'filepath' }],
rules: [{ type: "filepath" }],
})
p7bPath!: string;
@TaskInput({
title: '主机登录配置',
helper: 'access授权',
title: "主机登录配置",
helper: "access授权",
component: {
name: 'access-selector',
type: 'ssh',
name: "access-selector",
type: "ssh",
},
required: true,
})
accessId!: string;
@TaskInput({
title: '上传方式',
helper: '支持sftp或者scp\n需要有写入权限,如果没有,须先将证书上传到有权限的目录,再通过后置命令复制到目标路径',
value:"sftp",
title: "上传方式",
helper: "支持sftp或者scp\n需要有写入权限,如果没有,须先将证书上传到有权限的目录,再通过后置命令复制到目标路径",
value: "sftp",
component: {
name: 'a-select',
name: "a-select",
options: [
{ value: 'sftp', label: 'sftp' },
{ value: 'scp', label: 'scp' },
{ value: "sftp", label: "sftp" },
{ value: "scp", label: "scp" },
],
},
required: true,
})
uploadType: string = 'sftp';
uploadType = "sftp";
@TaskInput({
title: '自动创建远程目录',
helper: '是否自动创建远程目录,如果关闭则你需要自己确保远程目录存在',
title: "自动创建远程目录",
helper: "是否自动创建远程目录,如果关闭则你需要自己确保远程目录存在",
value: true,
component: {
name: 'a-switch',
vModel: 'checked',
name: "a-switch",
vModel: "checked",
},
})
mkdirs = true;
@TaskInput({
title: '前置命令',
title: "前置命令",
component: {
name: 'a-textarea',
vModel: 'value',
name: "a-textarea",
vModel: "value",
rows: 3,
placeholder: 'mkdir /app/ssl',
placeholder: "mkdir /app/ssl",
},
helper: '上传前执行脚本命令,做上传前的准备工作',
helper: "上传前执行脚本命令,做上传前的准备工作",
required: false,
})
scriptPre!: string;
@TaskInput({
title: '后置命令',
title: "后置命令",
component: {
name: 'a-textarea',
vModel: 'value',
name: "a-textarea",
vModel: "value",
rows: 5,
placeholder: 'systemctl restart nginx ',
placeholder: "systemctl restart nginx ",
},
helper: '上传后执行脚本命令,让证书生效(比如重启nginx),不填则不执行\n注意:sudo需要配置免密,不要使用-i这种交互式命令\n注意:如果目标主机是windows,且终端是cmd,系统会自动将多行命令通过“&&”连接成一行',
helper: "上传后执行脚本命令,让证书生效(比如重启nginx),不填则不执行\n注意:sudo需要配置免密,不要使用-i这种交互式命令\n注意:如果目标主机是windows,且终端是cmd,系统会自动将多行命令通过“&&”连接成一行",
required: false,
})
script!: string;
@TaskInput({
title: '注入环境变量',
title: "注入环境变量",
value: false,
component: {
name: 'a-switch',
vModel: 'checked',
name: "a-switch",
vModel: "checked",
},
helper: '是否将证书域名、路径等信息注入脚本执行环境变量中,具体的变量名称,可以运行后从日志中查看',
helper: "是否将证书域名、路径等信息注入脚本执行环境变量中,具体的变量名称,可以运行后从日志中查看",
required: false,
})
injectEnv!: string;
@TaskOutput({
title: '证书保存路径',
title: "证书保存路径",
})
hostCrtPath!: string;
@TaskOutput({
title: '私钥保存路径',
title: "私钥保存路径",
})
hostKeyPath!: string;
@TaskOutput({
title: '中间证书保存路径',
title: "中间证书保存路径",
})
hostIcPath!: string;
@TaskOutput({
title: 'PFX保存路径',
title: "PFX保存路径",
})
hostPfxPath!: string;
@TaskOutput({
title: 'DER保存路径',
title: "DER保存路径",
})
hostDerPath!: string;
@TaskOutput({
title: 'jks保存路径',
title: "jks保存路径",
})
hostJksPath!: string;
@TaskOutput({
title: '一体证书保存路径',
title: "一体证书保存路径",
})
hostOnePath!: string;
@TaskOutput({
title: 'p7b证书保存路径',
title: "p7b证书保存路径",
})
hostP7bPath!: string;
async onInstance() {}
async execute(): Promise<void> {
const { cert, accessId } = this;
let { crtPath, keyPath, icPath, pfxPath, derPath, jksPath, onePath,p7bPath } = this;
let { crtPath, keyPath, icPath, pfxPath, derPath, jksPath, onePath, p7bPath } = this;
const certReader = new CertReader(cert);
const executeCmd = async ( script:string)=> {
const executeCmd = async (script: string) => {
if (script && script?.trim()) {
const connectConf: SshAccess = await this.getAccess(accessId);
const sshClient = new SshClient(this.logger);
this.logger.info('执行脚本命令');
this.logger.info("执行脚本命令");
//环境变量
const env = {};
@@ -323,41 +322,41 @@ export class UploadCertToHostPlugin extends AbstractTaskPlugin {
env[`CERT_DOMAIN_${i}`] = domains[i];
}
//环境变量必须是string
env['CERT_EXPIRES'] = "" + dayjs(certReader.getCrtDetail().expires).unix();
env["CERT_EXPIRES"] = "" + dayjs(certReader.getCrtDetail().expires).unix();
env['HOST_CRT_PATH'] = this.hostCrtPath || '';
env['HOST_KEY_PATH'] = this.hostKeyPath || '';
env['HOST_IC_PATH'] = this.hostIcPath || '';
env['HOST_PFX_PATH'] = this.hostPfxPath || '';
env['HOST_DER_PATH'] = this.hostDerPath || '';
env['HOST_JKS_PATH'] = this.hostJksPath || '';
env['HOST_ONE_PATH'] = this.hostOnePath || '';
env['HOST_P7B_PATH'] = this.hostOnePath || '';
env["HOST_CRT_PATH"] = this.hostCrtPath || "";
env["HOST_KEY_PATH"] = this.hostKeyPath || "";
env["HOST_IC_PATH"] = this.hostIcPath || "";
env["HOST_PFX_PATH"] = this.hostPfxPath || "";
env["HOST_DER_PATH"] = this.hostDerPath || "";
env["HOST_JKS_PATH"] = this.hostJksPath || "";
env["HOST_ONE_PATH"] = this.hostOnePath || "";
env["HOST_P7B_PATH"] = this.hostOnePath || "";
}
const scripts = script.split('\n');
const scripts = script.split("\n");
await sshClient.exec({
connectConf,
script: scripts,
env,
});
}
}
};
const handle = async (opts: CertReaderHandleContext) => {
const { tmpCrtPath, tmpKeyPath, tmpDerPath, tmpJksPath, tmpPfxPath, tmpIcPath, tmpOnePath ,tmpP7bPath} = opts;
const { tmpCrtPath, tmpKeyPath, tmpDerPath, tmpJksPath, tmpPfxPath, tmpIcPath, tmpOnePath, tmpP7bPath } = opts;
if (accessId == null) {
this.logger.error('复制到当前主机功能已迁移到 “复制到本机”插件,请换成复制到本机插件');
this.logger.error("复制到当前主机功能已迁移到 “复制到本机”插件,请换成复制到本机插件");
return;
}
const connectConf: SshAccess = await this.getAccess(accessId);
const sshClient = new SshClient(this.logger);
if (!accessId) {
throw new Error('主机登录授权配置不能为空');
throw new Error("主机登录授权配置不能为空");
}
this.logger.info('准备上传文件到服务器');
this.logger.info("准备上传文件到服务器");
const transports: any = [];
if (crtPath) {
@@ -426,7 +425,7 @@ export class UploadCertToHostPlugin extends AbstractTaskPlugin {
});
}
this.logger.info('开始上传文件到服务器');
this.logger.info("开始上传文件到服务器");
await sshClient.uploadFiles({
connectConf,
transports,
@@ -434,7 +433,7 @@ export class UploadCertToHostPlugin extends AbstractTaskPlugin {
uploadType: this.uploadType,
});
this.logger.info('上传文件到服务器成功');
this.logger.info("上传文件到服务器成功");
//输出
this.hostCrtPath = crtPath;
this.hostKeyPath = keyPath;