Files
certd/packages/ui/certd-server/src/plugins/plugin-tencent/plugin/upload-to-tencent/index.ts
T

78 lines
1.9 KiB
TypeScript
Raw Normal View History

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({
name: 'UploadCertToTencent',
2024-12-26 01:32:52 +08:00
title: '腾讯云-上传证书到腾讯云',
2024-09-19 17:38:51 +08:00
icon: 'svg:icon-tencentcloud',
desc: '上传成功后输出:tencentCertId',
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({
title: 'Access授权',
helper: 'access授权',
2022-12-29 23:52:51 +08:00
component: {
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({
title: '域名证书',
helper: '请选择前置任务输出的域名证书',
2022-12-29 23:52:51 +08:00
component: {
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({
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
this.tencentCertId = tencentCertId;
2022-11-07 23:31:20 +08:00
}
checkRet(ret: any) {
if (!ret || ret.Error) {
throw new Error('执行失败:' + ret.Error.Code + ',' + ret.Error.Message);
2022-11-07 23:31:20 +08:00
}
}
}