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
+4 -4
View File
@@ -26,10 +26,10 @@
"@ant-design/icons-vue": "^6.1.0",
"@aws-sdk/client-s3": "^3.383.0",
"@aws-sdk/s3-request-presigner": "^3.383.0",
"@fast-crud/fast-crud": "^1.20.2",
"@fast-crud/fast-extends": "^1.20.2",
"@fast-crud/ui-antdv4": "^1.20.2",
"@fast-crud/ui-interface": "^1.20.2",
"@fast-crud/fast-crud": "^1.21.0",
"@fast-crud/fast-extends": "^1.21.0",
"@fast-crud/ui-antdv4": "^1.21.0",
"@fast-crud/ui-interface": "^1.21.0",
"@iconify/vue": "^4.1.1",
"@soerenmartius/vue3-clipboard": "^0.1.2",
"ant-design-vue": "^4.1.2",
@@ -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 = {
@@ -1,12 +1,6 @@
import _ from 'lodash';
import {
CreateRecordOptions,
IDnsProvider,
IsDnsProvider,
RemoveRecordOptions,
} from '@certd/plugin-cert';
import { Autowire, ILogger } from '@certd/pipeline';
import { CloudflareAccess } from './access';
import { AbstractDnsProvider, CreateRecordOptions, IsDnsProvider, RemoveRecordOptions } from "@certd/plugin-cert";
import { Autowire, HttpClient, ILogger } from "@certd/pipeline";
import { CloudflareAccess } from "./access";
// TODO 这里注册一个dnsProvider
@IsDnsProvider({
@@ -15,50 +9,41 @@ import { CloudflareAccess } from './access';
desc: 'cloudflare dns provider示例',
accessType: 'cloudflare',
})
export class CloudflareDnsProvider implements IDnsProvider {
export class CloudflareDnsProvider extends AbstractDnsProvider{
@Autowire()
logger! : ILogger;
access!: CloudflareAccess;
@Autowire()
logger!: ILogger;
http!: HttpClient;
async onInstance() {
const access: any = this.access;
this.logger.debug('access', access);
//初始化的操作
//...
//一些初始化的操作
this.access = this.ctx.access as CloudflareAccess;
this.http = this.ctx.http
}
async getDomainList(): Promise<any[]> {
// TODO 这里你要实现一个获取域名列表的方法
const access = this.access;
this.logger.debug('access', access);
return [];
}
async matchDomain(dnsRecord: string): Promise<any> {
const domainList = await this.getDomainList();
let domainRecord = null;
for (const item of domainList) {
//TODO 根据域名去匹配账户中是否有该域名, 这里不一定是item.name 具体要看你要实现的平台的接口而定
if (_.endsWith(dnsRecord + '.', item.name)) {
domainRecord = item;
break;
}
}
if (!domainRecord) {
this.logger.info('账户中域名列表:', domainList);
this.logger.error('找不到域名,请确认账户中是否真的有此域名');
throw new Error('can not find Domain:' + dnsRecord);
}
return domainRecord;
}
/**
* curl --request POST \
* --url https://api.cloudflare.com/client/v4/zones/zone_id/dns_records \
* --header 'Content-Type: application/json' \
* --header 'X-Auth-Email: ' \
* --data '{
* "content": "198.51.100.4",
* "name": "example.com",
* "proxied": false,
* "type": "A",
* "comment": "Domain verification record",
* "tags": [
* "owner:dns-team"
* ],
* "ttl": 60
* }'
*/
async createRecord(options: CreateRecordOptions): Promise<any> {
const { fullRecord, value, type } = options;
this.logger.info('添加域名解析:', fullRecord, value, type);
//先确定账户中是否有该域名
const domainRecord = await this.matchDomain(fullRecord);
this.logger.debug('matchDomain:', domainRecord);
const { fullRecord, value, type,domain } = options;
this.logger.info('添加域名解析:', fullRecord, value, type,domain);
this.http.post('https://api.cloudflare.com/client/v4/zones/zone_id/dns_records')
//TODO 然后调用接口,创建txt类型的dns解析记录
// .. 这里调用对应平台的后台接口
const access = this.access;
@@ -28,37 +28,10 @@ export class DemoDnsProvider implements IDnsProvider {
//...
}
async getDomainList(): Promise<any[]> {
// TODO 这里你要实现一个获取域名列表的方法
const access = this.access;
this.logger.debug('access', access);
return [];
}
async matchDomain(dnsRecord: string): Promise<any> {
const domainList = await this.getDomainList();
let domainRecord = null;
for (const item of domainList) {
//TODO 根据域名去匹配账户中是否有该域名, 这里不一定是item.name 具体要看你要实现的平台的接口而定
if (_.endsWith(dnsRecord + '.', item.name)) {
domainRecord = item;
break;
}
}
if (!domainRecord) {
this.logger.info('账户中域名列表:', domainList);
this.logger.error('找不到域名,请确认账户中是否真的有此域名');
throw new Error('can not find Domain:' + dnsRecord);
}
return domainRecord;
}
async createRecord(options: CreateRecordOptions): Promise<any> {
const { fullRecord, value, type } = options;
this.logger.info('添加域名解析:', fullRecord, value, type);
//先确定账户中是否有该域名
const domainRecord = await this.matchDomain(fullRecord);
this.logger.debug('matchDomain:', domainRecord);
const { fullRecord, value, type,domain } = options;
this.logger.info('添加域名解析:', fullRecord, value, type,domain);
//TODO 然后调用接口,创建txt类型的dns解析记录
// .. 这里调用对应平台的后台接口
const access = this.access;