mirror of https://github.com/certd/certd
pref: 优化部署到腾讯云任意资源插件,支持region,和资源类型选择
- 添加资源类型选择输入,支持多种腾讯云产品 -增加证书上传功能,支持直接上传证书到腾讯云 - 优化证书 ID 输入,支持选择上传任务或申请任务的输出- 添加 Region 输入,用于指定云资源所在地域 - 更新文档链接,提供更详细的参考信息pull/373/head
parent
37f160a452
commit
932780c578
|
@ -1,4 +1,6 @@
|
||||||
import {AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput} from '@certd/pipeline';
|
import {AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput} from '@certd/pipeline';
|
||||||
|
import { CertApplyPluginNames, CertInfo } from "@certd/plugin-cert";
|
||||||
|
import { TencentSslClient } from "@certd/plugin-lib";
|
||||||
|
|
||||||
@IsTaskPlugin({
|
@IsTaskPlugin({
|
||||||
name: 'DeployCertToTencentAll',
|
name: 'DeployCertToTencentAll',
|
||||||
|
@ -6,7 +8,7 @@ import {AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput}
|
||||||
needPlus: false,
|
needPlus: false,
|
||||||
icon: 'svg:icon-tencentcloud',
|
icon: 'svg:icon-tencentcloud',
|
||||||
group: pluginGroups.tencent.key,
|
group: pluginGroups.tencent.key,
|
||||||
desc: '需要【上传到腾讯云】作为前置任务',
|
desc: '支持负载均衡、CDN、DDoS、直播、点播、Web应用防火墙、API网关、TEO、容器服务、对象存储、轻应用服务器、云原生微服务、云开发',
|
||||||
default: {
|
default: {
|
||||||
strategy: {
|
strategy: {
|
||||||
runStrategy: RunStrategy.SkipWhenSucceed,
|
runStrategy: RunStrategy.SkipWhenSucceed,
|
||||||
|
@ -29,15 +31,70 @@ export class DeployCertToTencentAll extends AbstractTaskPlugin {
|
||||||
accessId!: string;
|
accessId!: string;
|
||||||
|
|
||||||
@TaskInput({
|
@TaskInput({
|
||||||
title: '腾讯云证书id',
|
title: '证书',
|
||||||
helper: '请选择“上传证书到腾讯云”前置任务的输出',
|
helper: '请选择"证书申请任务"或“上传证书到腾讯云”前置任务的输出',
|
||||||
component: {
|
component: {
|
||||||
name: 'output-selector',
|
name: 'output-selector',
|
||||||
from: 'UploadCertToTencent',
|
from: [...CertApplyPluginNames,'UploadCertToTencent'],
|
||||||
},
|
},
|
||||||
required: true,
|
required: true,
|
||||||
})
|
})
|
||||||
tencentCertId!: string;
|
tencentCertId!: string | CertInfo;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@TaskInput({
|
||||||
|
title: '资源类型',
|
||||||
|
component: {
|
||||||
|
name: 'a-select',
|
||||||
|
vModel: 'value',
|
||||||
|
allowClear: true,
|
||||||
|
//- clb
|
||||||
|
// - cdn
|
||||||
|
// - ddos
|
||||||
|
// - live
|
||||||
|
// - vod
|
||||||
|
// - waf
|
||||||
|
// - apigateway
|
||||||
|
// - teo
|
||||||
|
// - tke
|
||||||
|
// - cos
|
||||||
|
// - lighthouse
|
||||||
|
// - tse
|
||||||
|
// - tcb
|
||||||
|
options: [
|
||||||
|
{ value: 'clb',label: '负载均衡'},
|
||||||
|
{ value: 'cdn',label: 'CDN'},
|
||||||
|
{ value: 'ddos',label: 'DDoS'},
|
||||||
|
{ value: 'live',label: '直播'},
|
||||||
|
{ value: 'vod',label: '点播'},
|
||||||
|
{ value: 'waf',label: 'Web应用防火墙'},
|
||||||
|
{ value: 'apigateway',label: 'API网关'},
|
||||||
|
{ value: 'teo',label: 'TEO'},
|
||||||
|
{ value: 'tke',label: '容器服务'},
|
||||||
|
{ value: 'cos',label: '对象存储'},
|
||||||
|
{ value: 'lighthouse',label: '轻应用服务器'},
|
||||||
|
{ value: 'tse',label: '云原生微服务'},
|
||||||
|
{ value: 'tcb',label: '云开发'},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
helper: '',
|
||||||
|
required: true,
|
||||||
|
})
|
||||||
|
resourceType!: string;
|
||||||
|
|
||||||
|
@TaskInput({
|
||||||
|
title: 'Region',
|
||||||
|
component: {
|
||||||
|
name: 'a-input',
|
||||||
|
vModel: 'value',
|
||||||
|
allowClear: true,
|
||||||
|
},
|
||||||
|
helper: '当云资源类型传入clb、waf、apigateway、cos、lighthouse、tke、tse、tcb 时,公共参数Region必传。[参考文档](https://cloud.tencent.com/document/product/400/91667)',
|
||||||
|
})
|
||||||
|
region!: string;
|
||||||
|
|
||||||
|
|
||||||
@TaskInput({
|
@TaskInput({
|
||||||
title: '云资源实例Id列表',
|
title: '云资源实例Id列表',
|
||||||
|
@ -47,22 +104,22 @@ export class DeployCertToTencentAll extends AbstractTaskPlugin {
|
||||||
open: false,
|
open: false,
|
||||||
mode: 'tags',
|
mode: 'tags',
|
||||||
},
|
},
|
||||||
helper: '',
|
helper: '[参考文档](https://cloud.tencent.com/document/product/400/91667)',
|
||||||
})
|
})
|
||||||
instanceIdList!: string[];
|
instanceIdList!: string[];
|
||||||
|
|
||||||
async onInstance() {}
|
async onInstance() {}
|
||||||
async execute(): Promise<void> {
|
async execute(): Promise<void> {
|
||||||
const accessProvider = await this.getAccess(this.accessId);
|
const access = await this.getAccess(this.accessId);
|
||||||
|
|
||||||
const sdk = await import('tencentcloud-sdk-nodejs/tencentcloud/services/ssl/v20191205/index.js');
|
const sdk = await import('tencentcloud-sdk-nodejs/tencentcloud/services/ssl/v20191205/index.js');
|
||||||
const Client = sdk.v20191205.Client;
|
const Client = sdk.v20191205.Client;
|
||||||
const client = new Client({
|
const client = new Client({
|
||||||
credential: {
|
credential: {
|
||||||
secretId: accessProvider.secretId,
|
secretId: access.secretId,
|
||||||
secretKey: accessProvider.secretKey,
|
secretKey: access.secretKey,
|
||||||
},
|
},
|
||||||
region: '',
|
region: this.region,
|
||||||
profile: {
|
profile: {
|
||||||
httpProfile: {
|
httpProfile: {
|
||||||
endpoint: 'ssl.tencentcloudapi.com',
|
endpoint: 'ssl.tencentcloudapi.com',
|
||||||
|
@ -70,14 +127,25 @@ export class DeployCertToTencentAll extends AbstractTaskPlugin {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let certId:string = null
|
||||||
|
if (typeof certId === 'string') {
|
||||||
|
certId = this.tencentCertId as string;
|
||||||
|
} else {
|
||||||
|
//上传
|
||||||
|
certId = await this.uploadToTencent(access,this.tencentCertId as CertInfo);
|
||||||
|
}
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
CertificateId: this.tencentCertId,
|
CertificateId: certId,
|
||||||
|
ResourceType: this.resourceType,
|
||||||
InstanceIdList: this.instanceIdList,
|
InstanceIdList: this.instanceIdList,
|
||||||
|
IsCache:0,
|
||||||
};
|
};
|
||||||
|
|
||||||
const res = await client.DeployCertificateInstance(params);
|
const res = await client.DeployCertificateInstance(params);
|
||||||
this.checkRet(res);
|
this.checkRet(res);
|
||||||
this.logger.info('部署成功');
|
this.logger.info('部署成功,等待5s:',JSON.stringify(res));
|
||||||
|
await this.ctx.utils.sleep(5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
checkRet(ret: any) {
|
checkRet(ret: any) {
|
||||||
|
@ -85,4 +153,16 @@ export class DeployCertToTencentAll extends AbstractTaskPlugin {
|
||||||
throw new Error('执行失败:' + ret.Error.Code + ',' + ret.Error.Message);
|
throw new Error('执行失败:' + ret.Error.Code + ',' + ret.Error.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async uploadToTencent(access: any, cert: CertInfo) {
|
||||||
|
const sslClient = new TencentSslClient({
|
||||||
|
access,
|
||||||
|
logger: this.logger,
|
||||||
|
});
|
||||||
|
|
||||||
|
return await sslClient.uploadToTencent({
|
||||||
|
certName: this.appendTimeSuffix('certd'),
|
||||||
|
cert: cert,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue