2025-05-27 00:10:50 +08:00
|
|
|
import { AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput, TaskOutput } from "@certd/pipeline";
|
|
|
|
|
import { CertApplyPluginNames, CertReader } from "@certd/plugin-cert";
|
2025-12-31 17:01:37 +08:00
|
|
|
import { TencentAccess } from "../../../plugin-lib/tencent/access.js";
|
|
|
|
|
import { TencentSslClient } from "../../../plugin-lib/tencent/index.js";
|
2025-05-27 00:10:50 +08:00
|
|
|
|
2026-06-19 17:44:57 +08:00
|
|
|
const uploadCertToTencentDefine: any = {
|
2026-05-31 01:41:33 +08:00
|
|
|
name: "UploadCertToTencent",
|
|
|
|
|
title: "腾讯云-上传证书到腾讯云",
|
|
|
|
|
icon: "svg:icon-tencentcloud",
|
|
|
|
|
desc: "上传成功后输出:tencentCertId",
|
2024-07-21 02:26:03 +08:00
|
|
|
group: pluginGroups.tencent.key,
|
2026-06-19 17:44:57 +08:00
|
|
|
dependPlugins: {
|
|
|
|
|
"access:tencent": "*",
|
|
|
|
|
},
|
2022-12-29 23:52:51 +08:00
|
|
|
default: {
|
|
|
|
|
strategy: {
|
|
|
|
|
runStrategy: RunStrategy.SkipWhenSucceed,
|
2022-11-07 23:31:20 +08:00
|
|
|
},
|
2022-12-29 23:52:51 +08:00
|
|
|
},
|
2026-06-19 17:44:57 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
@IsTaskPlugin(uploadCertToTencentDefine)
|
2024-10-26 18:10:19 +08:00
|
|
|
export class UploadCertToTencent extends AbstractTaskPlugin {
|
2025-05-27 00:10:50 +08:00
|
|
|
// @TaskInput({ title: '证书名称' })
|
|
|
|
|
// name!: string;
|
2022-12-29 23:52:51 +08:00
|
|
|
|
|
|
|
|
@TaskInput({
|
2026-05-31 01:41:33 +08:00
|
|
|
title: "Access授权",
|
|
|
|
|
helper: "access授权",
|
2022-12-29 23:52:51 +08:00
|
|
|
component: {
|
2026-05-31 01:41:33 +08:00
|
|
|
name: "access-selector",
|
|
|
|
|
type: "tencent",
|
2022-11-07 23:31:20 +08:00
|
|
|
},
|
2022-12-29 23:52:51 +08:00
|
|
|
required: true,
|
|
|
|
|
})
|
|
|
|
|
accessId!: string;
|
|
|
|
|
|
|
|
|
|
@TaskInput({
|
2026-05-31 01:41:33 +08:00
|
|
|
title: "域名证书",
|
|
|
|
|
helper: "请选择前置任务输出的域名证书",
|
2022-12-29 23:52:51 +08:00
|
|
|
component: {
|
2026-05-31 01:41:33 +08:00
|
|
|
name: "output-selector",
|
2025-03-18 00:52:50 +08:00
|
|
|
from: [...CertApplyPluginNames],
|
2022-11-07 23:31:20 +08:00
|
|
|
},
|
2022-12-29 23:52:51 +08:00
|
|
|
required: true,
|
|
|
|
|
})
|
|
|
|
|
cert!: any;
|
|
|
|
|
|
|
|
|
|
@TaskOutput({
|
2026-05-31 01:41:33 +08:00
|
|
|
title: "上传成功后的腾讯云CertId",
|
2022-12-29 23:52:51 +08:00
|
|
|
})
|
|
|
|
|
tencentCertId?: string;
|
|
|
|
|
|
2024-08-28 14:40:50 +08:00
|
|
|
Client: any;
|
|
|
|
|
async onInstance() {
|
2026-06-19 17:44:57 +08:00
|
|
|
const sdk = await (this as any).importRuntime("tencentcloud-sdk-nodejs/tencentcloud/services/ssl/v20191205/index.js");
|
2024-08-28 14:40:50 +08:00
|
|
|
this.Client = sdk.v20191205.Client;
|
|
|
|
|
}
|
2022-12-29 23:52:51 +08:00
|
|
|
|
|
|
|
|
async execute(): Promise<void> {
|
2025-05-27 00:10:50 +08:00
|
|
|
const access = await this.getAccess<TencentAccess>(this.accessId);
|
|
|
|
|
const sslClient = new TencentSslClient({
|
|
|
|
|
access,
|
|
|
|
|
logger: this.logger,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const certReader = new CertReader(this.cert);
|
|
|
|
|
const tencentCertId = await sslClient.uploadToTencent({
|
|
|
|
|
certName: certReader.buildCertName(),
|
|
|
|
|
cert: this.cert,
|
|
|
|
|
});
|
2022-11-07 23:31:20 +08:00
|
|
|
|
2025-05-27 00:22:39 +08:00
|
|
|
this.tencentCertId = tencentCertId;
|
2022-11-07 23:31:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
checkRet(ret: any) {
|
|
|
|
|
if (!ret || ret.Error) {
|
2026-05-31 01:41:33 +08:00
|
|
|
throw new Error("执行失败:" + ret.Error.Code + "," + ret.Error.Message);
|
2022-11-07 23:31:20 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|