2024-08-13 20:30:42 +08:00
|
|
|
import { AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput, TaskOutput } from '@certd/pipeline';
|
2024-11-29 19:00:05 +08:00
|
|
|
import { AliyunAccess } from '@certd/plugin-lib';
|
|
|
|
|
import { AliyunSslClient } from '@certd/plugin-lib';
|
2025-05-22 23:21:32 +08:00
|
|
|
import { CertApplyPluginNames, CertReader } from "@certd/plugin-cert";
|
2024-10-25 16:51:36 +08:00
|
|
|
/**
|
|
|
|
|
* 华东1(杭州) cn-hangzhou cas.aliyuncs.com cas-vpc.cn-hangzhou.aliyuncs.com
|
|
|
|
|
* 马来西亚(吉隆坡) ap-southeast-3 cas.ap-southeast-3.aliyuncs.com cas-vpc.ap-southeast-3.aliyuncs.com
|
|
|
|
|
* 新加坡 ap-southeast-1 cas.ap-southeast-1.aliyuncs.com cas-vpc.ap-southeast-1.aliyuncs.com
|
|
|
|
|
* 印度尼西亚(雅加达) ap-southeast-5 cas.ap-southeast-5.aliyuncs.com cas-vpc.ap-southeast-5.aliyuncs.com
|
|
|
|
|
* 中国香港 cn-hongkong cas.cn-hongkong.aliyuncs.com cas-vpc.cn-hongkong.aliyuncs.com
|
|
|
|
|
* 欧洲与美洲
|
|
|
|
|
* 名称 区域 ID 服务地址 VPC 地址
|
|
|
|
|
* 德国(法兰克福) eu-central-1 cas.eu-central-1.aliyuncs.com
|
|
|
|
|
*/
|
|
|
|
|
const regionDict = [
|
|
|
|
|
{ value: 'cn-hangzhou', endpoint: 'cas.aliyuncs.com', label: 'cn-hangzhou-中国大陆' },
|
|
|
|
|
{ value: 'eu-central-1', endpoint: 'cas.eu-central-1.aliyuncs.com', label: 'eu-central-1-德国(法兰克福)' },
|
|
|
|
|
{ value: 'ap-southeast-1', endpoint: 'cas.ap-southeast-1.aliyuncs.com', label: 'ap-southeast-1-新加坡' },
|
|
|
|
|
{ value: 'ap-southeast-3', endpoint: 'cas.ap-southeast-3.aliyuncs.com', label: 'ap-southeast-3-马来西亚(吉隆坡)' },
|
|
|
|
|
{ value: 'ap-southeast-5', endpoint: 'cas.ap-southeast-5.aliyuncs.com', label: 'ap-southeast-5-印度尼西亚(雅加达)' },
|
|
|
|
|
{ value: 'cn-hongkong', endpoint: 'cas.cn-hongkong.aliyuncs.com', label: 'cn-hongkong-中国香港' },
|
|
|
|
|
];
|
2024-05-27 18:38:41 +08:00
|
|
|
|
|
|
|
|
@IsTaskPlugin({
|
|
|
|
|
name: 'uploadCertToAliyun',
|
2024-12-26 01:32:52 +08:00
|
|
|
title: '阿里云-上传证书到阿里云',
|
2025-03-24 21:27:31 +08:00
|
|
|
icon: 'svg:icon-aliyun',
|
2024-07-21 02:26:03 +08:00
|
|
|
group: pluginGroups.aliyun.key,
|
2024-10-25 16:51:36 +08:00
|
|
|
desc: '如果不想在阿里云上同一份证书上传多次,可以把此任务作为前置任务,其他阿里云任务证书那一项选择此任务的输出',
|
2024-05-27 18:38:41 +08:00
|
|
|
default: {
|
|
|
|
|
strategy: {
|
|
|
|
|
runStrategy: RunStrategy.SkipWhenSucceed,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
export class UploadCertToAliyun extends AbstractTaskPlugin {
|
|
|
|
|
@TaskInput({
|
|
|
|
|
title: '证书名称',
|
|
|
|
|
helper: '证书上传后将以此参数作为名称前缀',
|
|
|
|
|
})
|
|
|
|
|
name!: string;
|
|
|
|
|
|
|
|
|
|
@TaskInput({
|
|
|
|
|
title: '大区',
|
2024-08-06 11:23:23 +08:00
|
|
|
value: 'cn-hangzhou',
|
2024-05-27 18:38:41 +08:00
|
|
|
component: {
|
2024-08-13 20:30:42 +08:00
|
|
|
name: 'a-auto-complete',
|
2024-05-27 18:38:41 +08:00
|
|
|
vModel: 'value',
|
2024-10-25 16:51:36 +08:00
|
|
|
options: regionDict,
|
2024-05-27 18:38:41 +08:00
|
|
|
},
|
|
|
|
|
required: true,
|
|
|
|
|
})
|
|
|
|
|
regionId!: string;
|
|
|
|
|
|
|
|
|
|
@TaskInput({
|
|
|
|
|
title: '域名证书',
|
|
|
|
|
helper: '请选择前置任务输出的域名证书',
|
|
|
|
|
component: {
|
2024-10-07 03:21:16 +08:00
|
|
|
name: 'output-selector',
|
2025-03-18 00:52:50 +08:00
|
|
|
from: [...CertApplyPluginNames],
|
2024-05-27 18:38:41 +08:00
|
|
|
},
|
|
|
|
|
required: true,
|
|
|
|
|
})
|
|
|
|
|
cert!: any;
|
|
|
|
|
|
|
|
|
|
@TaskInput({
|
|
|
|
|
title: 'Access授权',
|
|
|
|
|
helper: '阿里云授权AccessKeyId、AccessKeySecret',
|
|
|
|
|
component: {
|
2024-10-07 03:21:16 +08:00
|
|
|
name: 'access-selector',
|
2024-05-27 18:38:41 +08:00
|
|
|
type: 'aliyun',
|
|
|
|
|
},
|
|
|
|
|
required: true,
|
|
|
|
|
})
|
|
|
|
|
accessId!: string;
|
|
|
|
|
|
|
|
|
|
@TaskOutput({
|
|
|
|
|
title: '上传成功后的阿里云CertId',
|
|
|
|
|
})
|
|
|
|
|
aliyunCertId!: string;
|
|
|
|
|
|
2024-08-13 20:30:42 +08:00
|
|
|
async onInstance() {}
|
2024-05-27 18:38:41 +08:00
|
|
|
|
|
|
|
|
async execute(): Promise<void> {
|
2024-09-02 23:46:28 +08:00
|
|
|
this.logger.info('开始部署证书到阿里云cdn');
|
2025-04-12 00:14:55 +08:00
|
|
|
const access: AliyunAccess = await this.getAccess(this.accessId);
|
2024-05-27 18:38:41 +08:00
|
|
|
|
2024-10-25 16:51:36 +08:00
|
|
|
let endpoint = '';
|
|
|
|
|
for (const region of regionDict) {
|
|
|
|
|
if (region.value === this.regionId) {
|
|
|
|
|
endpoint = region.endpoint;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const client = new AliyunSslClient({
|
|
|
|
|
access,
|
|
|
|
|
logger: this.logger,
|
|
|
|
|
endpoint,
|
|
|
|
|
});
|
2025-05-22 23:21:32 +08:00
|
|
|
const certName = this.buildCertName(CertReader.getMainDomain(this.cert.crt))
|
2024-10-25 16:51:36 +08:00
|
|
|
this.aliyunCertId = await client.uploadCert({
|
2025-05-22 23:21:32 +08:00
|
|
|
name: certName,
|
2024-10-25 16:51:36 +08:00
|
|
|
cert: this.cert,
|
2024-09-18 14:58:59 +08:00
|
|
|
});
|
2024-05-27 18:38:41 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//注册插件
|
|
|
|
|
new UploadCertToAliyun();
|