mirror of https://github.com/certd/certd
perf: 优化腾讯云CLB插件,支持非sni情况,sni情况支持填写多个域名
parent
1cb4a539cc
commit
635b042690
|
@ -6,7 +6,7 @@ import { TencentAccess } from '@certd/plugin-lib';
|
||||||
title: '腾讯云-部署到CLB',
|
title: '腾讯云-部署到CLB',
|
||||||
icon: 'svg:icon-tencentcloud',
|
icon: 'svg:icon-tencentcloud',
|
||||||
group: pluginGroups.tencent.key,
|
group: pluginGroups.tencent.key,
|
||||||
desc: '暂时只支持单向认证证书,暂时只支持通用负载均衡,必须开启sni',
|
desc: '暂时只支持单向认证证书,暂时只支持通用负载均衡',
|
||||||
default: {
|
default: {
|
||||||
strategy: {
|
strategy: {
|
||||||
runStrategy: RunStrategy.SkipWhenSucceed,
|
runStrategy: RunStrategy.SkipWhenSucceed,
|
||||||
|
@ -59,16 +59,22 @@ export class DeployCertToTencentCLB extends AbstractTaskPlugin {
|
||||||
|
|
||||||
@TaskInput({
|
@TaskInput({
|
||||||
title: '监听器ID',
|
title: '监听器ID',
|
||||||
helper: '如果没有配置,则根据域名或负载均衡id匹配监听器',
|
required: true,
|
||||||
})
|
})
|
||||||
listenerId!: string;
|
listenerId!: string;
|
||||||
|
|
||||||
@TaskInput({
|
@TaskInput({
|
||||||
title: '域名',
|
title: '域名',
|
||||||
required: true,
|
required: false,
|
||||||
helper: '要更新的支持https的负载均衡的域名',
|
component: {
|
||||||
|
name: 'a-select',
|
||||||
|
vModel: 'value',
|
||||||
|
open: false,
|
||||||
|
mode: 'tags',
|
||||||
|
},
|
||||||
|
helper: '如果开启了sni,则此项必须填写,未开启,则不要填写',
|
||||||
})
|
})
|
||||||
domain!: string;
|
domain!: string | string[];
|
||||||
|
|
||||||
@TaskInput({
|
@TaskInput({
|
||||||
title: '域名证书',
|
title: '域名证书',
|
||||||
|
@ -122,33 +128,48 @@ export class DeployCertToTencentCLB extends AbstractTaskPlugin {
|
||||||
|
|
||||||
async execute(): Promise<void> {
|
async execute(): Promise<void> {
|
||||||
const client = this.client;
|
const client = this.client;
|
||||||
const lastCertId = await this.getCertIdFromProps(client);
|
|
||||||
if (!this.domain) {
|
if (!this.domain || this.domain.length === 0) {
|
||||||
await this.updateListener(client);
|
await this.updateListener(client);
|
||||||
} else {
|
} else {
|
||||||
await this.updateByDomainAttr(client);
|
const domains = Array.isArray(this.domain) ? this.domain : [this.domain];
|
||||||
|
for (const domain of domains) {
|
||||||
|
this.logger.info(`开始更新域名证书:${domain},请确保已经开启了sni`);
|
||||||
|
const lastCertId = await this.getCertIdFromProps(client, domain);
|
||||||
|
|
||||||
|
await this.updateByDomainAttr(client, domain);
|
||||||
|
|
||||||
|
const checkDeployed = async (wait = 5) => {
|
||||||
|
await this.ctx.utils.sleep(wait * 1000);
|
||||||
|
this.logger.info(`等待${wait}秒`);
|
||||||
|
const newCertId = await this.getCertIdFromProps(client, domain);
|
||||||
|
this.logger.info(`oldCertId:${lastCertId} , newCertId:${newCertId}`);
|
||||||
|
if ((lastCertId && newCertId === lastCertId) || (!lastCertId && !newCertId)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
this.logger.info('腾讯云证书ID:', newCertId);
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
let count = 0;
|
||||||
|
while (true) {
|
||||||
|
count++;
|
||||||
|
const res = await checkDeployed(5);
|
||||||
|
if (res) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (count > 6) {
|
||||||
|
throw new Error('部署可能失败,请确认是否已开启sni');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
await this.ctx.utils.sleep(2000);
|
|
||||||
let newCertId = await this.getCertIdFromProps(client);
|
|
||||||
if ((lastCertId && newCertId === lastCertId) || (!lastCertId && !newCertId)) {
|
|
||||||
await this.ctx.utils.sleep(2000);
|
|
||||||
newCertId = await this.getCertIdFromProps(client);
|
|
||||||
}
|
|
||||||
if (newCertId === lastCertId) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.logger.info('腾讯云证书ID:', newCertId);
|
|
||||||
} catch (e) {
|
|
||||||
this.logger.warn('查询腾讯云证书失败', e);
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getCertIdFromProps(client: any) {
|
async getCertIdFromProps(client: any, domain: string) {
|
||||||
const listenerRet = await this.getListenerList(client, this.loadBalancerId, [this.listenerId]);
|
const listenerRet = await this.getListenerList(client, this.loadBalancerId, this.listenerId ? [this.listenerId] : null);
|
||||||
return this.getCertIdFromListener(listenerRet[0], this.domain);
|
return this.getCertIdFromListener(listenerRet[0], domain);
|
||||||
}
|
}
|
||||||
|
|
||||||
getCertIdFromListener(listener: any, domain: string) {
|
getCertIdFromListener(listener: any, domain: string) {
|
||||||
|
@ -178,21 +199,13 @@ export class DeployCertToTencentCLB extends AbstractTaskPlugin {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateByDomainAttr(client: any) {
|
async updateByDomainAttr(client: any, domain) {
|
||||||
const params: any = this.buildProps();
|
const params: any = this.buildProps();
|
||||||
params.Domain = this.domain;
|
|
||||||
|
params.Domain = domain;
|
||||||
const ret = await client.ModifyDomainAttributes(params);
|
const ret = await client.ModifyDomainAttributes(params);
|
||||||
this.checkRet(ret);
|
this.checkRet(ret);
|
||||||
this.logger.info(
|
this.logger.info('设置腾讯云CLB证书(sni)成功:', ret.RequestId, '->loadBalancerId:', this.loadBalancerId, 'listenerId', this.listenerId, 'domain:', domain);
|
||||||
'设置腾讯云CLB证书(sni)成功:',
|
|
||||||
ret.RequestId,
|
|
||||||
'->loadBalancerId:',
|
|
||||||
this.loadBalancerId,
|
|
||||||
'listenerId',
|
|
||||||
this.listenerId,
|
|
||||||
'domain:',
|
|
||||||
this.domain
|
|
||||||
);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
appendTimeSuffix(name: string) {
|
appendTimeSuffix(name: string) {
|
||||||
|
|
Loading…
Reference in New Issue