fix: 修复aliyun域名超过100个找不到域名的bug

This commit is contained in:
xiaojunnuo
2024-06-14 01:22:07 +08:00
parent ebf2a820cc
commit 5b1494b3ce
11 changed files with 183 additions and 188 deletions
@@ -1,13 +1,7 @@
import Core from '@alicloud/pop-core';
import _ from 'lodash';
import {
CreateRecordOptions,
IDnsProvider,
IsDnsProvider,
RemoveRecordOptions,
} from '@certd/plugin-cert';
import { Autowire, ILogger } from '@certd/pipeline';
import { AliyunAccess } from '../access';
import Core from "@alicloud/pop-core";
import { AbstractDnsProvider, CreateRecordOptions, IsDnsProvider, RemoveRecordOptions } from "@certd/plugin-cert";
import { Autowire, ILogger } from "@certd/pipeline";
import { AliyunAccess } from "../access";
@IsDnsProvider({
name: 'aliyun',
@@ -15,7 +9,7 @@ import { AliyunAccess } from '../access';
desc: '阿里云DNS解析提供商',
accessType: 'aliyun',
})
export class AliyunDnsProvider implements IDnsProvider {
export class AliyunDnsProvider extends AbstractDnsProvider{
client: any;
@Autowire()
access!: AliyunAccess;
@@ -30,71 +24,71 @@ export class AliyunDnsProvider implements IDnsProvider {
apiVersion: '2015-01-09',
});
}
async getDomainList() {
const params = {
RegionId: 'cn-hangzhou',
PageSize: 100,
};
const requestOption = {
method: 'POST',
};
const ret = await this.client.request(
'DescribeDomains',
params,
requestOption
);
return ret.Domains.Domain;
}
async matchDomain(dnsRecord: string) {
const list = await this.getDomainList();
let domain = null;
const domainList = [];
for (const item of list) {
domainList.push(item.DomainName);
if (_.endsWith(dnsRecord, item.DomainName)) {
domain = item.DomainName;
break;
}
}
if (!domain) {
throw new Error(
`can not find Domain :${dnsRecord} ,list: ${JSON.stringify(domainList)}`
);
}
return domain;
}
async getRecords(domain: string, rr: string, value: string) {
const params: any = {
RegionId: 'cn-hangzhou',
DomainName: domain,
RRKeyWord: rr,
ValueKeyWord: undefined,
};
if (value) {
params.ValueKeyWord = value;
}
const requestOption = {
method: 'POST',
};
const ret = await this.client.request(
'DescribeDomainRecords',
params,
requestOption
);
return ret.DomainRecords.Record;
}
//
// async getDomainList() {
// const params = {
// RegionId: 'cn-hangzhou',
// PageSize: 100,
// };
//
// const requestOption = {
// method: 'POST',
// };
//
// const ret = await this.client.request(
// 'DescribeDomains',
// params,
// requestOption
// );
// return ret.Domains.Domain;
// }
//
// async matchDomain(dnsRecord: string) {
// const list = await this.getDomainList();
// let domain = null;
// const domainList = [];
// for (const item of list) {
// domainList.push(item.DomainName);
// if (_.endsWith(dnsRecord, item.DomainName)) {
// domain = item.DomainName;
// break;
// }
// }
// if (!domain) {
// throw new Error(
// `can not find Domain :${dnsRecord} ,list: ${JSON.stringify(domainList)}`
// );
// }
// return domain;
// }
//
// async getRecords(domain: string, rr: string, value: string) {
// const params: any = {
// RegionId: 'cn-hangzhou',
// DomainName: domain,
// RRKeyWord: rr,
// ValueKeyWord: undefined,
// };
// if (value) {
// params.ValueKeyWord = value;
// }
//
// const requestOption = {
// method: 'POST',
// };
//
// const ret = await this.client.request(
// 'DescribeDomainRecords',
// params,
// requestOption
// );
// return ret.DomainRecords.Record;
// }
async createRecord(options: CreateRecordOptions): Promise<any> {
const { fullRecord, value, type } = options;
this.logger.info('添加域名解析:', fullRecord, value);
const domain = await this.matchDomain(fullRecord);
const { fullRecord, value, type,domain } = options;
this.logger.info('添加域名解析:', fullRecord, value,domain);
// const domain = await this.matchDomain(fullRecord);
const rr = fullRecord.replace('.' + domain, '');
const params = {