2024-08-23 18:02:14 +08:00
|
|
|
import { AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput } from '@certd/pipeline';
|
2024-09-19 17:38:51 +08:00
|
|
|
import { TencentAccess } from '@certd/plugin-plus';
|
2024-08-23 18:02:14 +08:00
|
|
|
|
|
|
|
|
@IsTaskPlugin({
|
2024-08-23 23:26:31 +08:00
|
|
|
name: 'DeployCertToTencentEO',
|
|
|
|
|
title: '部署到腾讯云EO',
|
2024-09-19 17:38:51 +08:00
|
|
|
icon: 'svg:icon-tencentcloud',
|
2024-08-23 23:26:31 +08:00
|
|
|
desc: '腾讯云边缘安全加速平台EO,必须配置上传证书到腾讯云任务',
|
2024-08-23 18:02:14 +08:00
|
|
|
group: pluginGroups.tencent.key,
|
|
|
|
|
default: {
|
|
|
|
|
strategy: {
|
|
|
|
|
runStrategy: RunStrategy.SkipWhenSucceed,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
})
|
2024-08-23 23:26:31 +08:00
|
|
|
export class DeployToEOPlugin extends AbstractTaskPlugin {
|
2024-08-23 18:02:14 +08:00
|
|
|
@TaskInput({
|
2024-08-23 23:26:31 +08:00
|
|
|
title: '已上传证书ID',
|
|
|
|
|
helper: '请选择前置任务上传到腾讯云的证书',
|
2024-08-23 18:02:14 +08:00
|
|
|
component: {
|
|
|
|
|
name: 'pi-output-selector',
|
2024-08-23 23:26:31 +08:00
|
|
|
from: 'UploadCertToTencent',
|
2024-08-23 18:02:14 +08:00
|
|
|
},
|
|
|
|
|
required: true,
|
|
|
|
|
})
|
2024-08-23 23:26:31 +08:00
|
|
|
certId!: string;
|
2024-08-23 18:02:14 +08:00
|
|
|
|
|
|
|
|
@TaskInput({
|
|
|
|
|
title: 'Access提供者',
|
|
|
|
|
helper: 'access 授权',
|
|
|
|
|
component: {
|
|
|
|
|
name: 'pi-access-selector',
|
|
|
|
|
type: 'tencent',
|
|
|
|
|
},
|
|
|
|
|
required: true,
|
|
|
|
|
})
|
|
|
|
|
accessId!: string;
|
|
|
|
|
|
2024-08-23 23:26:31 +08:00
|
|
|
@TaskInput({
|
|
|
|
|
title: '站点ID',
|
|
|
|
|
helper: '类似于zone-xxxx的字符串,在站点概览页面左上角,或者,站点列表页面站点名称下方',
|
2024-09-11 11:16:22 +08:00
|
|
|
required: true,
|
2024-08-23 23:26:31 +08:00
|
|
|
})
|
|
|
|
|
zoneId!: string;
|
|
|
|
|
|
2024-08-23 18:02:14 +08:00
|
|
|
@TaskInput({
|
|
|
|
|
title: '证书名称',
|
|
|
|
|
helper: '证书上传后将以此参数作为名称前缀',
|
|
|
|
|
})
|
|
|
|
|
certName!: string;
|
|
|
|
|
|
|
|
|
|
@TaskInput({
|
|
|
|
|
title: 'cdn加速域名',
|
2024-08-23 23:26:31 +08:00
|
|
|
component: {
|
|
|
|
|
name: 'a-select',
|
|
|
|
|
vModel: 'value',
|
|
|
|
|
mode: 'tags',
|
|
|
|
|
open: false,
|
|
|
|
|
},
|
|
|
|
|
helper: '支持多个域名',
|
2024-08-23 18:02:14 +08:00
|
|
|
rules: [{ required: true, message: '该项必填' }],
|
|
|
|
|
})
|
2024-08-23 23:26:31 +08:00
|
|
|
domainNames!: string[];
|
2024-08-23 18:02:14 +08:00
|
|
|
|
|
|
|
|
// @TaskInput({
|
|
|
|
|
// title: "CDN接口",
|
|
|
|
|
// helper: "CDN接口端点",
|
|
|
|
|
// component: {
|
|
|
|
|
// name: "a-select",
|
|
|
|
|
// type: "tencent",
|
|
|
|
|
// },
|
|
|
|
|
// required: true,
|
|
|
|
|
// })
|
|
|
|
|
// endpoint!: string;
|
2024-08-28 14:40:50 +08:00
|
|
|
Client: any;
|
2024-08-23 18:02:14 +08:00
|
|
|
|
2024-08-28 14:40:50 +08:00
|
|
|
async onInstance() {
|
|
|
|
|
const sdk = await import('tencentcloud-sdk-nodejs/tencentcloud/services/teo/v20220901/index.js');
|
|
|
|
|
this.Client = sdk.v20220901.Client;
|
|
|
|
|
}
|
2024-08-23 18:02:14 +08:00
|
|
|
|
|
|
|
|
async execute(): Promise<void> {
|
|
|
|
|
const accessProvider: TencentAccess = (await this.accessService.getById(this.accessId)) as TencentAccess;
|
|
|
|
|
const client = this.getClient(accessProvider);
|
|
|
|
|
const params = this.buildParams();
|
|
|
|
|
await this.doRequest(client, params);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getClient(accessProvider: TencentAccess) {
|
2024-08-28 14:40:50 +08:00
|
|
|
const TeoClient = this.Client;
|
2024-08-23 18:02:14 +08:00
|
|
|
|
|
|
|
|
const clientConfig = {
|
|
|
|
|
credential: {
|
|
|
|
|
secretId: accessProvider.secretId,
|
|
|
|
|
secretKey: accessProvider.secretKey,
|
|
|
|
|
},
|
|
|
|
|
region: '',
|
|
|
|
|
profile: {
|
|
|
|
|
httpProfile: {
|
2024-08-23 23:26:31 +08:00
|
|
|
endpoint: 'teo.tencentcloudapi.com',
|
2024-08-23 18:02:14 +08:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
2024-08-23 23:26:31 +08:00
|
|
|
return new TeoClient(clientConfig);
|
2024-08-23 18:02:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buildParams() {
|
|
|
|
|
return {
|
2024-08-23 23:26:31 +08:00
|
|
|
ZoneId: this.zoneId,
|
|
|
|
|
Hosts: this.domainNames,
|
|
|
|
|
Mode: 'sslcert',
|
|
|
|
|
ServerCertInfo: [
|
|
|
|
|
{
|
|
|
|
|
CertId: this.certId,
|
2024-08-23 18:02:14 +08:00
|
|
|
},
|
2024-08-23 23:26:31 +08:00
|
|
|
],
|
2024-08-23 18:02:14 +08:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async doRequest(client: any, params: any) {
|
2024-08-23 23:26:31 +08:00
|
|
|
const ret = await client.ModifyHostsCertificate(params);
|
2024-08-23 18:02:14 +08:00
|
|
|
this.checkRet(ret);
|
2024-08-23 23:26:31 +08:00
|
|
|
this.logger.info('设置腾讯云EO证书成功:', ret.RequestId);
|
2024-08-23 18:02:14 +08:00
|
|
|
return ret.RequestId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
checkRet(ret: any) {
|
|
|
|
|
if (!ret || ret.Error) {
|
|
|
|
|
throw new Error('执行失败:' + ret.Error.Code + ',' + ret.Error.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|