mirror of
https://github.com/certd/certd.git
synced 2026-05-16 21:27:34 +08:00
perf: 支持部署到阿里云NLB、SLB
This commit is contained in:
@@ -1,22 +1,21 @@
|
||||
import { IsTaskPlugin, pluginGroups, RunStrategy, TaskInput } from '@certd/pipeline';
|
||||
import { AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput } from '@certd/pipeline';
|
||||
import { CertInfo } from '@certd/plugin-cert';
|
||||
import { AliyunAccess, AliyunClient, AliyunSslClient, createCertDomainGetterInputDefine, createRemoteSelectInputDefine } from '@certd/plugin-lib';
|
||||
import { AbstractPlusTaskPlugin } from '@certd/plugin-plus';
|
||||
|
||||
@IsTaskPlugin({
|
||||
name: 'AliyunDeployCertToALB',
|
||||
title: '阿里云-部署至阿里云ALB',
|
||||
name: 'AliyunDeployCertToLB',
|
||||
title: '阿里云-部署至ALB(应用负载均衡)',
|
||||
icon: 'ant-design:aliyun-outlined',
|
||||
group: pluginGroups.aliyun.key,
|
||||
desc: '部署证书到阿里云ALB,仅更新监听器的默认证书',
|
||||
needPlus: true,
|
||||
desc: 'ALB,更新监听器的默认证书',
|
||||
needPlus: false,
|
||||
default: {
|
||||
strategy: {
|
||||
runStrategy: RunStrategy.SkipWhenSucceed,
|
||||
},
|
||||
},
|
||||
})
|
||||
export class AliyunDeployCertToALB extends AbstractPlusTaskPlugin {
|
||||
export class AliyunDeployCertToALB extends AbstractTaskPlugin {
|
||||
@TaskInput({
|
||||
title: '域名证书',
|
||||
helper: '请选择证书申请任务输出的域名证书\n或者选择前置任务“上传证书到阿里云”任务的证书ID,可以减少上传到阿里云的证书数量',
|
||||
@@ -44,7 +43,7 @@ export class AliyunDeployCertToALB extends AbstractPlusTaskPlugin {
|
||||
|
||||
@TaskInput(
|
||||
createRemoteSelectInputDefine({
|
||||
title: 'ALB所在地区',
|
||||
title: 'LB所在地区',
|
||||
typeName: 'AliyunDeployCertToALB',
|
||||
multi: false,
|
||||
action: AliyunDeployCertToALB.prototype.onGetRegionList.name,
|
||||
@@ -56,7 +55,7 @@ export class AliyunDeployCertToALB extends AbstractPlusTaskPlugin {
|
||||
@TaskInput(
|
||||
createRemoteSelectInputDefine({
|
||||
title: '负载均衡列表',
|
||||
helper: '要部署证书的ALB负载均衡',
|
||||
helper: '要部署证书的负载均衡ID',
|
||||
typeName: 'AliyunDeployCertToALB',
|
||||
action: AliyunDeployCertToALB.prototype.onGetLoadBalanceList.name,
|
||||
watches: ['regionId'],
|
||||
@@ -93,29 +92,31 @@ export class AliyunDeployCertToALB extends AbstractPlusTaskPlugin {
|
||||
|
||||
async onInstance() {}
|
||||
|
||||
async getALBClient(access: AliyunAccess, region: string) {
|
||||
async getLBClient(access: AliyunAccess, region: string) {
|
||||
const client = new AliyunClient({ logger: this.logger });
|
||||
|
||||
const version = '2020-06-16';
|
||||
await client.init({
|
||||
accessKeyId: access.accessKeyId,
|
||||
accessKeySecret: access.accessKeySecret,
|
||||
//https://wafopenapi.cn-hangzhou.aliyuncs.com
|
||||
endpoint: `https://alb.${region}.aliyuncs.com`,
|
||||
apiVersion: '2020-06-16',
|
||||
apiVersion: version,
|
||||
});
|
||||
return client;
|
||||
}
|
||||
|
||||
async execute(): Promise<void> {
|
||||
this.logger.info('开始部署证书到阿里云ALB');
|
||||
this.logger.info(`开始部署证书到阿里云(alb)`);
|
||||
const access = await this.accessService.getById<AliyunAccess>(this.accessId);
|
||||
const certId = await this.getAliyunCertId(access);
|
||||
|
||||
const client = await this.getALBClient(access, this.regionId);
|
||||
const client = await this.getLBClient(access, this.regionId);
|
||||
|
||||
for (const listener of this.listeners) {
|
||||
//查询原来的证书
|
||||
|
||||
const params = {
|
||||
let params: any = {};
|
||||
params = {
|
||||
ListenerId: listener,
|
||||
Certificates: [
|
||||
{
|
||||
@@ -155,7 +156,7 @@ export class AliyunDeployCertToALB extends AbstractPlusTaskPlugin {
|
||||
throw new Error('请选择Access授权');
|
||||
}
|
||||
const access = await this.accessService.getById<AliyunAccess>(this.accessId);
|
||||
const client = await this.getALBClient(access, 'cn-shanghai');
|
||||
const client = await this.getLBClient(access, 'cn-shanghai');
|
||||
|
||||
const res = await client.request('DescribeRegions', {});
|
||||
this.checkRet(res);
|
||||
@@ -180,7 +181,7 @@ export class AliyunDeployCertToALB extends AbstractPlusTaskPlugin {
|
||||
throw new Error('请先选择地区');
|
||||
}
|
||||
const access = await this.accessService.getById<AliyunAccess>(this.accessId);
|
||||
const client = await this.getALBClient(access, this.regionId);
|
||||
const client = await this.getLBClient(access, this.regionId);
|
||||
|
||||
const params = {
|
||||
MaxResults: 100,
|
||||
@@ -208,7 +209,7 @@ export class AliyunDeployCertToALB extends AbstractPlusTaskPlugin {
|
||||
throw new Error('请先选择地区');
|
||||
}
|
||||
const access = await this.accessService.getById<AliyunAccess>(this.accessId);
|
||||
const client = await this.getALBClient(access, this.regionId);
|
||||
const client = await this.getLBClient(access, this.regionId);
|
||||
|
||||
const params: any = {
|
||||
MaxResults: 100,
|
||||
@@ -223,7 +224,7 @@ export class AliyunDeployCertToALB extends AbstractPlusTaskPlugin {
|
||||
}
|
||||
|
||||
return res.Listeners.map((item: any) => {
|
||||
const label = `${item.ListenerId}<${item.ListenerDescription}}:${item.LoadBalancerId}>`;
|
||||
const label = `${item.ListenerId}<${item.ListenerDescription}@${item.LoadBalancerId}>`;
|
||||
return {
|
||||
label: label,
|
||||
value: item.ListenerId,
|
||||
|
||||
Reference in New Issue
Block a user