mirror of
https://github.com/certd/certd.git
synced 2026-04-03 14:10:54 +08:00
perf: 多个dns 提供商支持导入域名
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { HttpClient, ILogger, utils } from "@certd/basic";
|
||||
import { IAccess, IServiceGetter, Pager, PageRes, Registrable } from "@certd/pipeline";
|
||||
import { IAccess, IServiceGetter, Pager, PageRes, PageSearch, Registrable } from "@certd/pipeline";
|
||||
|
||||
export type DnsProviderDefine = Registrable & {
|
||||
accessType: string;
|
||||
@@ -57,7 +57,7 @@ export interface IDnsProvider<T = any> {
|
||||
//中文域名是否需要punycode转码,如果返回True,则使用punycode来添加解析记录,否则使用中文域名添加解析记录
|
||||
usePunyCode(): boolean;
|
||||
|
||||
getDomainListPage(pager: Pager): Promise<PageRes<DomainRecord>>;
|
||||
getDomainListPage(pager: PageSearch): Promise<PageRes<DomainRecord>>;
|
||||
}
|
||||
|
||||
export interface ISubDomainsGetter {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Pager, PageRes } from "@certd/pipeline";
|
||||
import { Pager, PageRes, PageSearch } from "@certd/pipeline";
|
||||
import { CreateRecordOptions, DnsProviderContext, DnsProviderDefine, DomainRecord, IDnsProvider, RemoveRecordOptions } from "./api.js";
|
||||
import { dnsProviderRegistry } from "./registry.js";
|
||||
import { HttpClient, ILogger } from "@certd/basic";
|
||||
@@ -46,7 +46,7 @@ export abstract class AbstractDnsProvider<T = any> implements IDnsProvider<T> {
|
||||
|
||||
abstract removeRecord(options: RemoveRecordOptions<T>): Promise<void>;
|
||||
|
||||
async getDomainListPage(pager: Pager): Promise<PageRes<DomainRecord>> {
|
||||
async getDomainListPage(req: PageSearch): Promise<PageRes<DomainRecord>> {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import {createAxiosService, HttpClient, ILogger} from "@certd/basic";
|
||||
import {Dns51Access} from "./access.js";
|
||||
import qs from "qs"
|
||||
import { Pager, PageRes } from "@certd/pipeline";
|
||||
import { createAxiosService, HttpClient, ILogger } from "@certd/basic";
|
||||
import { PageRes, PageSearch } from "@certd/pipeline";
|
||||
import { DomainRecord } from "@certd/plugin-lib/dist/cert/dns-provider/api.js";
|
||||
import qs from "qs";
|
||||
import { Dns51Access } from "./access.js";
|
||||
export class Dns51Client {
|
||||
logger: ILogger;
|
||||
access: Dns51Access;
|
||||
@@ -237,8 +237,8 @@ _token: ieOfM21eDd9nWJv3OZtMJF6ogDsnPKQHJ17dlMck
|
||||
|
||||
}
|
||||
|
||||
async getDomainListPage(pager: Pager): Promise<PageRes<DomainRecord>> {
|
||||
if (pager.pageNo >=2) { //不知道翻页查询的参数是什么
|
||||
async getDomainListPage(req: PageSearch): Promise<PageRes<DomainRecord>> {
|
||||
if (req.pageNo >=2) { //不知道翻页查询的参数是什么
|
||||
return {
|
||||
total: 0,
|
||||
list: []
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { AbstractDnsProvider, CreateRecordOptions, DomainRecord, IsDnsProvider, RemoveRecordOptions } from "@certd/plugin-cert";
|
||||
|
||||
import { PageRes, PageSearch } from "@certd/pipeline";
|
||||
import { Dns51Access } from "./access.js";
|
||||
import { Dns51Client } from "./client.js";
|
||||
import { Pager, PageRes } from "@certd/pipeline";
|
||||
|
||||
export type Dns51Record = {
|
||||
id: number;
|
||||
@@ -94,8 +94,8 @@ export class Dns51DnsProvider extends AbstractDnsProvider<Dns51Record> {
|
||||
this.logger.info(`删除域名解析成功:fullRecord=${fullRecord},id=${id}`);
|
||||
}
|
||||
|
||||
async getDomainListPage(pager: Pager): Promise<PageRes<DomainRecord>> {
|
||||
return await this.client.getDomainListPage(pager)
|
||||
async getDomainListPage(req: PageSearch): Promise<PageRes<DomainRecord>> {
|
||||
return await this.client.getDomainListPage(req)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
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 } from '@certd/pipeline';
|
||||
import { Pager, PageRes, PageSearch } from '@certd/pipeline';
|
||||
|
||||
|
||||
@IsDnsProvider({
|
||||
@@ -155,7 +155,8 @@ export class AliyunDnsProvider extends AbstractDnsProvider {
|
||||
}
|
||||
}
|
||||
|
||||
async getDomainListPage(pager: Pager) :Promise<PageRes<DomainRecord>> {
|
||||
async getDomainListPage(req: PageSearch) :Promise<PageRes<DomainRecord>> {
|
||||
const pager = new Pager(req);
|
||||
const params = {
|
||||
RegionId: 'cn-hangzhou',
|
||||
PageSize: pager.pageSize,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { AbstractDnsProvider, CreateRecordOptions, IsDnsProvider, RemoveRecordOptions } from '@certd/plugin-cert';
|
||||
import { AbstractDnsProvider, CreateRecordOptions, DomainRecord, IsDnsProvider, RemoveRecordOptions } from '@certd/plugin-cert';
|
||||
import { TencentAccess } from '../../plugin-lib/tencent/index.js';
|
||||
import { Pager, PageRes, PageSearch } from '@certd/pipeline';
|
||||
|
||||
@IsDnsProvider({
|
||||
name: 'tencent',
|
||||
@@ -93,5 +94,26 @@ export class TencentDnsProvider extends AbstractDnsProvider {
|
||||
this.logger.info('删除域名解析成功:', fullRecord, value);
|
||||
return ret;
|
||||
}
|
||||
|
||||
async getDomainListPage(req: PageSearch): Promise<PageRes<DomainRecord>> {
|
||||
|
||||
const pager = new Pager(req);
|
||||
|
||||
const params:any = {
|
||||
Offset: pager.getOffset(),
|
||||
Limit: pager.pageSize,
|
||||
};
|
||||
if (req.searchKey) {
|
||||
params.Keyword = req.searchKey;
|
||||
}
|
||||
const ret = await this.client.DescribeDomainList(params);
|
||||
let list = ret.DomainList || [];
|
||||
list = list.map((item) => ({
|
||||
id: item.DomainId,
|
||||
domain: item.Name,
|
||||
}));
|
||||
const total = ret.DomainCountInfo?.AllTotal || list.length
|
||||
return {total,list,};
|
||||
}
|
||||
}
|
||||
new TencentDnsProvider();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {http} from "@certd/basic";
|
||||
import querystring from "querystring";
|
||||
import {VolcengineOpts} from "./ve-client.js";
|
||||
import { Pager, PageSearch } from "@certd/pipeline";
|
||||
|
||||
|
||||
export type VolcengineReq = {
|
||||
@@ -79,7 +80,6 @@ export class VolcengineDnsClient {
|
||||
}
|
||||
|
||||
|
||||
// 列出域名解析记录
|
||||
async findDomain(domain: string) {
|
||||
const req: VolcengineReq = {
|
||||
method: "POST",
|
||||
@@ -97,5 +97,41 @@ export class VolcengineDnsClient {
|
||||
|
||||
return this.doRequest(req);
|
||||
}
|
||||
|
||||
async getDomainList(page: PageSearch) {
|
||||
const pager = new Pager(page)
|
||||
const body:any = {
|
||||
SearchMode: "like",
|
||||
PageNumber: pager.pageNo,
|
||||
PageSize: pager.pageSize,
|
||||
}
|
||||
if (page.searchKey) {
|
||||
body.Key = page.searchKey
|
||||
}
|
||||
const req: VolcengineReq = {
|
||||
method: "POST",
|
||||
region: "cn-beijing",
|
||||
service: "dns",
|
||||
query: {
|
||||
Action: "ListZones",
|
||||
Version: "2018-08-01",
|
||||
},
|
||||
body:body
|
||||
};
|
||||
|
||||
const res = await this.doRequest(req);
|
||||
let list = res.Result?.Zones || []
|
||||
list = list.map((item:any) => {
|
||||
return {
|
||||
id: item.ZID,
|
||||
domain: item.ZoneName,
|
||||
}
|
||||
})
|
||||
const total = res.Result?.Total|| list.length
|
||||
return {
|
||||
list,
|
||||
total
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import { AbstractDnsProvider, CreateRecordOptions, IsDnsProvider, RemoveRecordOp
|
||||
|
||||
import { VolcengineDnsClient } from "./dns-client.js";
|
||||
import { VolcengineAccess } from "./access.js";
|
||||
import { PageSearch } from "@certd/pipeline";
|
||||
|
||||
@IsDnsProvider({
|
||||
name: "volcengine",
|
||||
@@ -88,6 +89,10 @@ export class VolcengineDnsProvider extends AbstractDnsProvider {
|
||||
body
|
||||
});
|
||||
}
|
||||
|
||||
async getDomainListPage(page: PageSearch) {
|
||||
return await this.client.getDomainList(page)
|
||||
}
|
||||
}
|
||||
|
||||
new VolcengineDnsProvider();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { HttpRequestConfig } from '@certd/basic';
|
||||
import { IsAccess, AccessInput, BaseAccess } from '@certd/pipeline';
|
||||
import { IsAccess, AccessInput, BaseAccess, PageSearch, Pager } from '@certd/pipeline';
|
||||
import qs from 'qs';
|
||||
import iconv from 'iconv-lite';
|
||||
/**
|
||||
@@ -133,7 +133,7 @@ export class WestAccess extends BaseAccess {
|
||||
return "ok";
|
||||
}
|
||||
|
||||
await this.getDomainList();
|
||||
await this.getDomainList({pageNo:1,pageSize:1});
|
||||
return "ok";
|
||||
}
|
||||
|
||||
@@ -166,14 +166,15 @@ export class WestAccess extends BaseAccess {
|
||||
return res;
|
||||
}
|
||||
|
||||
async getDomainList() {
|
||||
async getDomainList(req: PageSearch) {
|
||||
const pager = new Pager(req)
|
||||
const res = await this.doRequest({
|
||||
url: '/v2/domain',
|
||||
method: 'GET',
|
||||
data:{
|
||||
act:'getdomains',
|
||||
limit:1,
|
||||
page:1
|
||||
limit: pager.pageSize,
|
||||
page: pager.pageNo,
|
||||
}
|
||||
});
|
||||
return res;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { AbstractDnsProvider, CreateRecordOptions, IsDnsProvider, RemoveRecordOptions } from '@certd/plugin-cert';
|
||||
import { WestDnsProviderDomain } from './dns-provider-domain.js';
|
||||
import { PageRes, PageSearch } from '@certd/pipeline';
|
||||
import { AbstractDnsProvider, CreateRecordOptions, DomainRecord, IsDnsProvider, RemoveRecordOptions } from '@certd/plugin-cert';
|
||||
import { WestAccess } from './access.js';
|
||||
import { WestDnsProviderDomain } from './dns-provider-domain.js';
|
||||
|
||||
type westRecord = {
|
||||
// 这里定义Record记录的数据结构,跟对应云平台接口返回值一样即可,一般是拿到id就行,用于删除txt解析记录,清理申请痕迹
|
||||
@@ -128,6 +129,10 @@ export class WestDnsProvider extends AbstractDnsProvider<westRecord> {
|
||||
const result = res.result;
|
||||
this.logger.info('删除域名解析成功:', fullRecord, value, JSON.stringify(result));
|
||||
}
|
||||
|
||||
async getDomainListPage(req: PageSearch): Promise<PageRes<DomainRecord>> {
|
||||
return await this.access.getDomainList(req);
|
||||
}
|
||||
}
|
||||
|
||||
//TODO 实例化这个provider,将其自动注册到系统中
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { AbstractDnsProvider, CreateRecordOptions, IsDnsProvider, RemoveRecordOptions } from "@certd/plugin-cert";
|
||||
import { AbstractDnsProvider, CreateRecordOptions, DomainRecord, IsDnsProvider, RemoveRecordOptions } from "@certd/plugin-cert";
|
||||
import { XinnetAgentAccess } from "./access-agent.js";
|
||||
import { PageRes, PageSearch } from "@certd/pipeline";
|
||||
|
||||
export type XinnetAgentRecord = {
|
||||
recordId: number;
|
||||
@@ -81,9 +82,20 @@ line 是 string 线路 只能传"默认"
|
||||
domainName: domainName
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
async getDomainListPage(req: PageSearch): Promise<PageRes<DomainRecord>> {
|
||||
const res = await this.access.getDomainList(req);
|
||||
const list = res.list.map((item) => ({
|
||||
domain: item.domainName,
|
||||
id: item.domainName
|
||||
}));
|
||||
return {
|
||||
list: list || [],
|
||||
total: res.totalRows || 0
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//实例化这个provider,将其自动注册到系统中
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { AbstractDnsProvider, CreateRecordOptions, IsDnsProvider, RemoveRecordOptions } from "@certd/plugin-cert";
|
||||
import { AbstractDnsProvider, CreateRecordOptions, DomainRecord, IsDnsProvider, RemoveRecordOptions } from "@certd/plugin-cert";
|
||||
import { XinnetAccess } from "./access.js";
|
||||
import { XinnetClient } from "@certd/plugin-plus";
|
||||
import { PageRes, PageSearch } from "@certd/pipeline";
|
||||
|
||||
export type XinnetRecord = {
|
||||
recordId: number;
|
||||
@@ -104,6 +105,26 @@ export class XinnetProvider extends AbstractDnsProvider<XinnetRecord> {
|
||||
|
||||
|
||||
}
|
||||
|
||||
async getDomainListPage(req: PageSearch): Promise<PageRes<DomainRecord>> {
|
||||
|
||||
const client = new XinnetClient({
|
||||
logger: this.logger,
|
||||
access: this.access,
|
||||
http: this.http
|
||||
});
|
||||
|
||||
const res = await client.getDomainList(req);
|
||||
|
||||
const list = res.list.map((item) => ({
|
||||
domain: item.domainName,
|
||||
id: item.domainName
|
||||
}));
|
||||
return {
|
||||
list: list || [],
|
||||
total: res.totalRows || 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//实例化这个provider,将其自动注册到系统中
|
||||
|
||||
Reference in New Issue
Block a user