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";
|
|
|
|
|
import { TencentAccess, TencentSslClient } from "@certd/plugin-lib";
|
|
|
|
|
|
2022-12-29 23:52:51 +08:00
|
|
|
@IsTaskPlugin({
|
2024-05-27 18:38:41 +08:00
|
|
|
name: 'UploadCertToTencent',
|
2024-12-26 01:32:52 +08:00
|
|
|
title: '腾讯云-上传证书到腾讯云',
|
2024-09-19 17:38:51 +08:00
|
|
|
icon: 'svg:icon-tencentcloud',
|
2024-05-27 18:38:41 +08:00
|
|
|
desc: '上传成功后输出:tencentCertId',
|
2024-07-21 02:26:03 +08:00
|
|
|
group: pluginGroups.tencent.key,
|
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
|
|
|
},
|
|
|
|
|
})
|
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({
|
2024-05-27 18:38:41 +08:00
|
|
|
title: 'Access授权',
|
|
|
|
|
helper: 'access授权',
|
2022-12-29 23:52:51 +08:00
|
|
|
component: {
|
2024-10-07 03:21:16 +08:00
|
|
|
name: 'access-selector',
|
2024-05-27 18:38:41 +08:00
|
|
|
type: 'tencent',
|
2022-11-07 23:31:20 +08:00
|
|
|
},
|
2022-12-29 23:52:51 +08:00
|
|
|
required: true,
|
|
|
|
|
})
|
|
|
|
|
accessId!: string;
|
|
|
|
|
|
|
|
|
|
@TaskInput({
|
2024-05-27 18:38:41 +08:00
|
|
|
title: '域名证书',
|
|
|
|
|
helper: '请选择前置任务输出的域名证书',
|
2022-12-29 23:52:51 +08:00
|
|
|
component: {
|
2024-10-07 03:21:16 +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({
|
2024-05-27 18:38:41 +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() {
|
|
|
|
|
const sdk = await import('tencentcloud-sdk-nodejs/tencentcloud/services/ssl/v20191205/index.js');
|
|
|
|
|
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) {
|
2024-05-27 18:38:41 +08:00
|
|
|
throw new Error('执行失败:' + ret.Error.Code + ',' + ret.Error.Message);
|
2022-11-07 23:31:20 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|