perf: 部署到阿里云支持选择bucket和域名

v2
xiaojunnuo 2025-08-07 18:30:47 +08:00
parent 79addfda42
commit 013b9c4c7c
3 changed files with 111 additions and 44 deletions

View File

@ -100,6 +100,8 @@ const getOptions = async () => {
const list = res?.list || res || []; const list = res?.list || res || [];
if (list.length > 0) { if (list.length > 0) {
message.value = "获取数据成功,请从下拉框中选择"; message.value = "获取数据成功,请从下拉框中选择";
} else {
message.value = "获取数据成功,没有数据";
} }
optionsRef.value = list; optionsRef.value = list;

View File

@ -145,6 +145,8 @@ const getOptions = async () => {
const list = res?.list || res || []; const list = res?.list || res || [];
if (list.length > 0) { if (list.length > 0) {
message.value = "获取数据成功,请从下拉框中选择"; message.value = "获取数据成功,请从下拉框中选择";
} else {
message.value = "获取数据成功,没有数据";
} }
optionsRef.value = list; optionsRef.value = list;
pagerRef.value.total = list.length; pagerRef.value.total = list.length;

View File

@ -1,7 +1,14 @@
import { AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput } from '@certd/pipeline'; import {AbstractTaskPlugin, IsTaskPlugin, Pager, pluginGroups, RunStrategy, TaskInput} from '@certd/pipeline';
import {AliyunAccess, AliyunSslClient} from '@certd/plugin-lib'; import {
AliyunAccess,
AliyunSslClient,
createCertDomainGetterInputDefine,
createRemoteSelectInputDefine
} from '@certd/plugin-lib';
import {CertInfo, CertReader} from '@certd/plugin-cert'; import {CertInfo, CertReader} from '@certd/plugin-cert';
import { CertApplyPluginNames} from '@certd/plugin-cert'; import { CertApplyPluginNames} from '@certd/plugin-cert';
import {optionsUtils} from "@certd/basic/dist/utils/util.options.js";
import {isArray} from "lodash-es";
@IsTaskPlugin({ @IsTaskPlugin({
name: 'DeployCertToAliyunOSS', name: 'DeployCertToAliyunOSS',
title: '阿里云-部署证书至OSS', title: '阿里云-部署证书至OSS',
@ -15,6 +22,22 @@ import { CertApplyPluginNames} from '@certd/plugin-cert';
}, },
}) })
export class DeployCertToAliyunOSS extends AbstractTaskPlugin { export class DeployCertToAliyunOSS extends AbstractTaskPlugin {
@TaskInput({
title: '域名证书',
helper: '请选择前置任务输出的域名证书',
component: {
name: 'output-selector',
from: [...CertApplyPluginNames,"uploadCertToAliyun"],
},
required: true,
})
cert!: CertInfo | string;
@TaskInput(createCertDomainGetterInputDefine({ props: { required: false } }))
certDomains!: string[];
@TaskInput({ @TaskInput({
title: '大区', title: '大区',
component: { component: {
@ -72,12 +95,14 @@ export class DeployCertToAliyunOSS extends AbstractTaskPlugin {
}) })
bucket!: string; bucket!: string;
@TaskInput({ @TaskInput(createRemoteSelectInputDefine({
title: '绑定的域名', title: '绑定的域名',
helper: '你在阿里云OSS上绑定的域名比如:certd.docmirror.cn', helper: '你在阿里云OSS上绑定的域名比如:certd.docmirror.cn',
required: true, required: true,
}) action: DeployCertToAliyunOSS.prototype.onGetDomainList.name,
domainName!: string; watches: ['certDomains', 'accessId','bucket'],
}))
domainName!: string | string[];
@TaskInput({ @TaskInput({
@ -86,16 +111,7 @@ export class DeployCertToAliyunOSS extends AbstractTaskPlugin {
}) })
certName!: string; certName!: string;
@TaskInput({
title: '域名证书',
helper: '请选择前置任务输出的域名证书',
component: {
name: 'output-selector',
from: [...CertApplyPluginNames,"uploadCertToAliyun"],
},
required: true,
})
cert!: CertInfo | string;
@TaskInput({ @TaskInput({
title: '证书服务接入点', title: '证书服务接入点',
@ -134,10 +150,52 @@ export class DeployCertToAliyunOSS extends AbstractTaskPlugin {
await this.getAliyunCertId(access) await this.getAliyunCertId(access)
this.logger.info(`bucket: ${this.bucket}, region: ${this.region}, domainName: ${this.domainName}`); this.logger.info(`bucket: ${this.bucket}, region: ${this.region}, domainName: ${this.domainName}`);
const client = await this.getClient(access); const client = await this.getClient(access);
await this.doRequest(client, {}); if (typeof this.domainName === "string"){
this.domainName = [this.domainName];
}
for (const domainName of this.domainName) {
this.logger.info("开始部署证书到阿里云oss自定义域名:", domainName)
await this.updateCert(domainName,client, {});
}
this.logger.info('部署完成'); this.logger.info('部署完成');
} }
async updateCert(domainName:string,client: any, params: any) {
params = client._bucketRequestParams('POST', this.bucket, {
cname: '',
comp: 'add',
});
let certStr = ""
if (typeof this.cert === "object" ){
certStr = `
<PrivateKey>${this.cert.key}</PrivateKey>
<Certificate>${this.cert.crt}</Certificate>
`
}else{
certStr = `<CertId>${this.cert}-${this.casRegion}</CertId>`
}
const xml = `
<BucketCnameConfiguration>
<Cname>
<Domain>${domainName}</Domain>
<CertificateConfiguration>
${certStr}
<Force>true</Force>
</CertificateConfiguration>
</Cname>
</BucketCnameConfiguration>`;
params.content = xml;
params.mime = 'xml';
params.successStatuses = [200];
const res = await client.request(params);
this.checkRet(res);
return res;
}
async getAliyunCertId(access: AliyunAccess) { async getAliyunCertId(access: AliyunAccess) {
let certId: any = this.cert; let certId: any = this.cert;
let certName: any = this.appendTimeSuffix("certd"); let certName: any = this.appendTimeSuffix("certd");
@ -181,8 +239,7 @@ export class DeployCertToAliyunOSS extends AbstractTaskPlugin {
}); });
} }
async onGetBucketList(data: any) { async onGetBucketList(data: Pager) {
console.log('data', data)
const access = (await this.getAccess(this.accessId)) as AliyunAccess; const access = (await this.getAccess(this.accessId)) as AliyunAccess;
const client = await this.getClient(access); const client = await this.getClient(access);
@ -199,43 +256,49 @@ export class DeployCertToAliyunOSS extends AbstractTaskPlugin {
.map(bucket => ({label: `${bucket.name}<${bucket.region}>`, value: bucket.name})); .map(bucket => ({label: `${bucket.name}<${bucket.region}>`, value: bucket.name}));
} }
async doRequest(client: any, params: any) { async onGetDomainList(data: any) {
params = client._bucketRequestParams('POST', this.bucket, {
cname: '',
comp: 'add',
});
let certStr = "" const access = (await this.getAccess(this.accessId)) as AliyunAccess;
if (typeof this.cert === "object" ){ const client = await this.getClient(access);
certStr = `
<PrivateKey>${this.cert.key}</PrivateKey> const res = await this.doListCnameRequest(client,this.bucket)
<Certificate>${this.cert.crt}</Certificate> let domains = res.data?.Cname
` if (domains == null || domains.length === 0){
}else{ return []
certStr = `<CertId>${this.cert}-${this.casRegion}</CertId>` }
if (!isArray(domains)){
domains = [domains]
} }
const xml = ` const options = domains.map((item: any) => {
<BucketCnameConfiguration> return {
<Cname> value: item.Domain,
<Domain>${this.domainName}</Domain> label: item.Domain,
<CertificateConfiguration> domain: item.Domain,
${certStr} };
<Force>true</Force> });
</CertificateConfiguration> return optionsUtils.buildGroupOptions(options, this.certDomains);
</Cname> }
</BucketCnameConfiguration>`;
params.content = xml;
async doListCnameRequest(client: any,bucket:string) {
const params = client._bucketRequestParams('GET', this.bucket, {
cname: '',
bucket
});
params.mime = 'xml'; params.mime = 'xml';
params.successStatuses = [200]; params.successStatuses = [200];
params.xmlResponse = true;
const res = await client.request(params); const res = await client.request(params);
this.checkRet(res); this.checkRet(res);
return res; return res;
} }
checkRet(ret: any) { checkRet(ret: any) {
if (ret.Code != null) { if (ret.Code != null || ret.status!==200) {
throw new Error('执行失败:' + ret.Message); throw new Error('执行失败:' + ret.Message || ret.data);
} }
} }
} }