mirror of
https://github.com/certd/certd.git
synced 2026-07-15 02:07:38 +08:00
chore: format
This commit is contained in:
+33
-41
@@ -1,27 +1,23 @@
|
||||
import { PageRes, PageSearch } from '@certd/pipeline';
|
||||
import { AbstractDnsProvider, CreateRecordOptions, DomainRecord, IsDnsProvider, RemoveRecordOptions } from '@certd/plugin-cert';
|
||||
import { AliesaAccess } from '../../plugin-lib/aliyun/index.js';
|
||||
import { AliyunClientV2 } from '../../plugin-lib/aliyun/lib/aliyun-client-v2.js';
|
||||
|
||||
import { PageRes, PageSearch } from "@certd/pipeline";
|
||||
import { AbstractDnsProvider, CreateRecordOptions, DomainRecord, IsDnsProvider, RemoveRecordOptions } from "@certd/plugin-cert";
|
||||
import { AliesaAccess } from "../../plugin-lib/aliyun/index.js";
|
||||
import { AliyunClientV2 } from "../../plugin-lib/aliyun/lib/aliyun-client-v2.js";
|
||||
|
||||
@IsDnsProvider({
|
||||
name: 'aliesa',
|
||||
title: '阿里ESA',
|
||||
desc: '阿里ESA DNS解析',
|
||||
accessType: 'aliesa',
|
||||
icon: 'svg:icon-aliyun',
|
||||
name: "aliesa",
|
||||
title: "阿里ESA",
|
||||
desc: "阿里ESA DNS解析",
|
||||
accessType: "aliesa",
|
||||
icon: "svg:icon-aliyun",
|
||||
order: 0,
|
||||
})
|
||||
export class AliesaDnsProvider extends AbstractDnsProvider {
|
||||
|
||||
|
||||
client: AliyunClientV2
|
||||
client: AliyunClientV2;
|
||||
async onInstance() {
|
||||
const access : AliesaAccess = this.ctx.access as AliesaAccess
|
||||
this.client = await access.getEsaClient()
|
||||
const access: AliesaAccess = this.ctx.access as AliesaAccess;
|
||||
this.client = await access.getEsaClient();
|
||||
}
|
||||
|
||||
|
||||
async getSiteItem(domain: string) {
|
||||
const ret = await this.client.doRequest({
|
||||
// 接口名称
|
||||
@@ -39,26 +35,23 @@ export class AliesaDnsProvider extends AbstractDnsProvider {
|
||||
SiteName: domain,
|
||||
// ["SiteSearchType"] = "exact";
|
||||
SiteSearchType: "exact",
|
||||
AccessType: "NS"
|
||||
}
|
||||
}
|
||||
})
|
||||
const list = ret.Sites
|
||||
AccessType: "NS",
|
||||
},
|
||||
},
|
||||
});
|
||||
const list = ret.Sites;
|
||||
if (list?.length === 0) {
|
||||
throw new Error(`阿里云ESA中不存在此域名站点:${domain},请确认域名已添加到ESA中,且为NS接入方式`);
|
||||
}
|
||||
return list[0]
|
||||
|
||||
return list[0];
|
||||
}
|
||||
|
||||
async createRecord(options: CreateRecordOptions): Promise<any> {
|
||||
const { fullRecord, value, type, domain } = options;
|
||||
this.logger.info('添加域名解析:', fullRecord, value, domain);
|
||||
|
||||
|
||||
const siteItem = await this.getSiteItem(domain)
|
||||
const siteId = siteItem.SiteId
|
||||
this.logger.info("添加域名解析:", fullRecord, value, domain);
|
||||
|
||||
const siteItem = await this.getSiteItem(domain);
|
||||
const siteId = siteItem.SiteId;
|
||||
|
||||
const res = await this.client.doRequest({
|
||||
action: "CreateRecord",
|
||||
@@ -72,16 +65,15 @@ export class AliesaDnsProvider extends AbstractDnsProvider {
|
||||
// queries["Ttl"] = 1231311;
|
||||
Ttl: 100,
|
||||
Data: JSON.stringify({ Value: value }),
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
this.logger.info('添加域名解析成功:', fullRecord, value, res.RecordId);
|
||||
this.logger.info("添加域名解析成功:", fullRecord, value, res.RecordId);
|
||||
return {
|
||||
RecordId: res.RecordId,
|
||||
SiteId: siteId,
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
async removeRecord(options: RemoveRecordOptions<any>): Promise<any> {
|
||||
@@ -91,16 +83,16 @@ export class AliesaDnsProvider extends AbstractDnsProvider {
|
||||
action: "DeleteRecord",
|
||||
version: "2024-09-10",
|
||||
data: {
|
||||
query: {
|
||||
RecordId: record.RecordId,
|
||||
}
|
||||
}
|
||||
})
|
||||
this.logger.info('删除域名解析成功:', record.RecordId);
|
||||
query: {
|
||||
RecordId: record.RecordId,
|
||||
},
|
||||
},
|
||||
});
|
||||
this.logger.info("删除域名解析成功:", record.RecordId);
|
||||
}
|
||||
|
||||
async getDomainListPage(req: PageSearch): Promise<PageRes<DomainRecord>> {
|
||||
return await this.ctx.access.getDomainListPage(req)
|
||||
return await this.ctx.access.getDomainListPage(req);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+49
-54
@@ -1,29 +1,27 @@
|
||||
import { AbstractDnsProvider, CreateRecordOptions, DomainRecord, IsDnsProvider, RemoveRecordOptions } from '@certd/plugin-cert';
|
||||
import { AliyunAccess } from '../../plugin-lib/aliyun/access/aliyun-access.js';
|
||||
import { AliyunClient } from '../../plugin-lib/aliyun/index.js';
|
||||
import { Pager, PageRes, PageSearch } from '@certd/pipeline';
|
||||
|
||||
import { AbstractDnsProvider, CreateRecordOptions, DomainRecord, IsDnsProvider, RemoveRecordOptions } from "@certd/plugin-cert";
|
||||
import { AliyunAccess } from "../../plugin-lib/aliyun/access/aliyun-access.js";
|
||||
import { AliyunClient } from "../../plugin-lib/aliyun/index.js";
|
||||
import { Pager, PageRes, PageSearch } from "@certd/pipeline";
|
||||
|
||||
@IsDnsProvider({
|
||||
name: 'aliyun',
|
||||
title: '阿里云',
|
||||
desc: '阿里云DNS解析提供商',
|
||||
accessType: 'aliyun',
|
||||
icon: 'svg:icon-aliyun',
|
||||
order:0,
|
||||
name: "aliyun",
|
||||
title: "阿里云",
|
||||
desc: "阿里云DNS解析提供商",
|
||||
accessType: "aliyun",
|
||||
icon: "svg:icon-aliyun",
|
||||
order: 0,
|
||||
})
|
||||
export class AliyunDnsProvider extends AbstractDnsProvider {
|
||||
|
||||
client: any;
|
||||
async onInstance() {
|
||||
const access: AliyunAccess = this.ctx.access as AliyunAccess
|
||||
const access: AliyunAccess = this.ctx.access as AliyunAccess;
|
||||
|
||||
this.client = new AliyunClient({ logger: this.logger });
|
||||
await this.client.init({
|
||||
accessKeyId: access.accessKeyId,
|
||||
accessKeySecret: access.accessKeySecret,
|
||||
endpoint: 'https://alidns.aliyuncs.com',
|
||||
apiVersion: '2015-01-09',
|
||||
endpoint: "https://alidns.aliyuncs.com",
|
||||
apiVersion: "2015-01-09",
|
||||
});
|
||||
}
|
||||
//
|
||||
@@ -88,11 +86,11 @@ export class AliyunDnsProvider extends AbstractDnsProvider {
|
||||
// }
|
||||
|
||||
async createRecord(options: CreateRecordOptions): Promise<any> {
|
||||
const { fullRecord,hostRecord, value, type, domain } = options;
|
||||
this.logger.info('添加域名解析:', fullRecord, value, domain);
|
||||
const { fullRecord, hostRecord, value, type, domain } = options;
|
||||
this.logger.info("添加域名解析:", fullRecord, value, domain);
|
||||
// const domain = await this.matchDomain(fullRecord);
|
||||
const params = {
|
||||
RegionId: 'cn-hangzhou',
|
||||
RegionId: "cn-hangzhou",
|
||||
DomainName: domain,
|
||||
RR: hostRecord,
|
||||
Type: type,
|
||||
@@ -101,31 +99,31 @@ export class AliyunDnsProvider extends AbstractDnsProvider {
|
||||
};
|
||||
|
||||
const requestOption = {
|
||||
method: 'POST',
|
||||
method: "POST",
|
||||
};
|
||||
try {
|
||||
const ret = await this.client.request('AddDomainRecord', params, requestOption);
|
||||
this.logger.info('添加域名解析成功:', JSON.stringify(options), ret.RecordId);
|
||||
const ret = await this.client.request("AddDomainRecord", params, requestOption);
|
||||
this.logger.info("添加域名解析成功:", JSON.stringify(options), ret.RecordId);
|
||||
return ret.RecordId;
|
||||
} catch (e: any) {
|
||||
if (e.code === 'DomainRecordDuplicate') {
|
||||
if (e.code === "DomainRecordDuplicate") {
|
||||
return;
|
||||
}
|
||||
if(e.code === "LastOperationNotFinished"){
|
||||
this.logger.info('上一个操作还未完成,5s后重试')
|
||||
await this.ctx.utils.sleep(5000)
|
||||
return this.createRecord(options)
|
||||
if (e.code === "LastOperationNotFinished") {
|
||||
this.logger.info("上一个操作还未完成,5s后重试");
|
||||
await this.ctx.utils.sleep(5000);
|
||||
return this.createRecord(options);
|
||||
}
|
||||
if (e.code === 'SignatureDoesNotMatch') {
|
||||
this.logger.error('阿里云账号的AccessKeyId或AccessKeySecret错误,请检查AccessKey是否被删除、过期、或者选择了错误的授权记录');
|
||||
if (e.code === "SignatureDoesNotMatch") {
|
||||
this.logger.error("阿里云账号的AccessKeyId或AccessKeySecret错误,请检查AccessKey是否被删除、过期、或者选择了错误的授权记录");
|
||||
}
|
||||
this.logger.info('添加域名解析出错', e);
|
||||
this.logger.info("添加域名解析出错", e);
|
||||
this.resolveError(e, options);
|
||||
}
|
||||
}
|
||||
|
||||
resolveError(e: any, req: CreateRecordOptions) {
|
||||
if (e.message?.indexOf('The specified domain name does not exist') > -1) {
|
||||
if (e.message?.indexOf("The specified domain name does not exist") > -1) {
|
||||
throw new Error(`阿里云账号中不存在此域名:${req.domain}`);
|
||||
}
|
||||
throw e;
|
||||
@@ -134,53 +132,50 @@ export class AliyunDnsProvider extends AbstractDnsProvider {
|
||||
const { fullRecord, value } = options.recordReq;
|
||||
const record = options.recordRes;
|
||||
const params = {
|
||||
RegionId: 'cn-hangzhou',
|
||||
RegionId: "cn-hangzhou",
|
||||
RecordId: record,
|
||||
};
|
||||
|
||||
const requestOption = {
|
||||
method: 'POST',
|
||||
method: "POST",
|
||||
};
|
||||
try{
|
||||
const ret = await this.client.request('DeleteDomainRecord', params, requestOption);
|
||||
this.logger.info('删除域名解析成功:', fullRecord, value, ret.RecordId);
|
||||
try {
|
||||
const ret = await this.client.request("DeleteDomainRecord", params, requestOption);
|
||||
this.logger.info("删除域名解析成功:", fullRecord, value, ret.RecordId);
|
||||
return ret.RecordId;
|
||||
}catch (e) {
|
||||
if(e.code === "LastOperationNotFinished"){
|
||||
this.logger.info('上一个操作还未完成,5s后重试')
|
||||
await this.ctx.utils.sleep(5000)
|
||||
return this.removeRecord(options)
|
||||
} catch (e) {
|
||||
if (e.code === "LastOperationNotFinished") {
|
||||
this.logger.info("上一个操作还未完成,5s后重试");
|
||||
await this.ctx.utils.sleep(5000);
|
||||
return this.removeRecord(options);
|
||||
}
|
||||
throw e
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
async getDomainListPage(req: PageSearch) :Promise<PageRes<DomainRecord>> {
|
||||
async getDomainListPage(req: PageSearch): Promise<PageRes<DomainRecord>> {
|
||||
const pager = new Pager(req);
|
||||
const params = {
|
||||
RegionId: 'cn-hangzhou',
|
||||
RegionId: "cn-hangzhou",
|
||||
PageSize: pager.pageSize,
|
||||
PageNumber: pager.pageNo,
|
||||
};
|
||||
|
||||
const requestOption = {
|
||||
method: 'POST',
|
||||
method: "POST",
|
||||
};
|
||||
|
||||
const ret = await this.client.request(
|
||||
'DescribeDomains',
|
||||
params,
|
||||
requestOption
|
||||
);
|
||||
const list = ret.Domains?.Domain?.map(item => ({
|
||||
id: item.DomainId,
|
||||
domain: item.DomainName,
|
||||
})) || []
|
||||
const ret = await this.client.request("DescribeDomains", params, requestOption);
|
||||
const list =
|
||||
ret.Domains?.Domain?.map(item => ({
|
||||
id: item.DomainId,
|
||||
domain: item.DomainName,
|
||||
})) || [];
|
||||
|
||||
return {
|
||||
list,
|
||||
total: ret.TotalCount,
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
import './aliyun-dns-provider.js';
|
||||
import './aliesa-dns-provider.js';
|
||||
import "./aliyun-dns-provider.js";
|
||||
import "./aliesa-dns-provider.js";
|
||||
|
||||
Reference in New Issue
Block a user