mirror of
https://github.com/certd/certd.git
synced 2026-04-30 01:07:28 +08:00
perf: 所有的dnsprovider 支持导入域名列表
This commit is contained in:
+36
-2
@@ -1,5 +1,5 @@
|
|||||||
import { IAccessService } from '@certd/pipeline';
|
import { IAccessService, Pager, PageRes, PageSearch } from '@certd/pipeline';
|
||||||
import { AbstractDnsProvider, CreateRecordOptions, IsDnsProvider, RemoveRecordOptions } from '@certd/plugin-cert';
|
import { AbstractDnsProvider, CreateRecordOptions, DomainRecord, IsDnsProvider, RemoveRecordOptions } from '@certd/plugin-cert';
|
||||||
import { AliesaAccess, AliyunAccess } from '../../plugin-lib/aliyun/index.js';
|
import { AliesaAccess, AliyunAccess } from '../../plugin-lib/aliyun/index.js';
|
||||||
import { AliyunClientV2 } from '../../plugin-lib/aliyun/lib/aliyun-client-v2.js';
|
import { AliyunClientV2 } from '../../plugin-lib/aliyun/lib/aliyun-client-v2.js';
|
||||||
|
|
||||||
@@ -101,6 +101,40 @@ export class AliesaDnsProvider extends AbstractDnsProvider {
|
|||||||
})
|
})
|
||||||
this.logger.info('删除域名解析成功:', record.RecordId);
|
this.logger.info('删除域名解析成功:', record.RecordId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getDomainListPage(req: PageSearch): Promise<PageRes<DomainRecord>> {
|
||||||
|
const pager = new Pager(req)
|
||||||
|
const ret = await this.client.doRequest({
|
||||||
|
// 接口名称
|
||||||
|
action: "ListSites",
|
||||||
|
// 接口版本
|
||||||
|
version: "2024-09-10",
|
||||||
|
// 接口协议
|
||||||
|
protocol: "HTTPS",
|
||||||
|
// 接口 HTTP 方法
|
||||||
|
method: "GET",
|
||||||
|
authType: "AK",
|
||||||
|
style: "RPC",
|
||||||
|
data: {
|
||||||
|
query: {
|
||||||
|
SiteName: req.searchKey,
|
||||||
|
// ["SiteSearchType"] = "exact";
|
||||||
|
SiteSearchType: "fuzzy",
|
||||||
|
AccessType: "NS",
|
||||||
|
PageSize: pager.pageSize,
|
||||||
|
PageNumber: pager.pageNo,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
const list = ret.Sites?.map(item => ({
|
||||||
|
domain: item.SiteName,
|
||||||
|
id: item.SiteId,
|
||||||
|
}))
|
||||||
|
return {
|
||||||
|
list: list || [],
|
||||||
|
total: ret.TotalCount,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
new AliesaDnsProvider();
|
new AliesaDnsProvider();
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { AbstractDnsProvider, CreateRecordOptions, IsDnsProvider, RemoveRecordOptions } from '@certd/plugin-cert';
|
import { AbstractDnsProvider, CreateRecordOptions, DomainRecord, IsDnsProvider, RemoveRecordOptions } from '@certd/plugin-cert';
|
||||||
import { AwsClient } from './libs/aws-client.js';
|
import { AwsClient } from './libs/aws-client.js';
|
||||||
import { AwsAccess } from './access.js';
|
import { AwsAccess } from './access.js';
|
||||||
|
import { PageRes, PageSearch } from '@certd/pipeline';
|
||||||
|
|
||||||
|
|
||||||
@IsDnsProvider({
|
@IsDnsProvider({
|
||||||
@@ -57,6 +58,10 @@ export class AwsRoute53Provider extends AbstractDnsProvider {
|
|||||||
this.logger.warn(`删除域名解析失败:${e.message} : ${hostedZoneId} ${fullRecord} ${value} ${type} `, );
|
this.logger.warn(`删除域名解析失败:${e.message} : ${hostedZoneId} ${fullRecord} ${value} ${type} `, );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getDomainListPage(req: PageSearch): Promise<PageRes<DomainRecord>> {
|
||||||
|
return await this.client.route53ListHostedZonesPage(req);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
new AwsRoute53Provider();
|
new AwsRoute53Provider();
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
// 导入所需的 SDK 模块
|
// 导入所需的 SDK 模块
|
||||||
import { AwsAccess } from '../access.js';
|
import { AwsAccess } from '../access.js';
|
||||||
import { CertInfo } from '@certd/plugin-cert';
|
import { CertInfo, DomainRecord } from '@certd/plugin-cert';
|
||||||
import { ILogger, utils } from '@certd/basic';
|
import { ILogger, utils } from '@certd/basic';
|
||||||
|
import { PageRes, PageSearch } from '@certd/pipeline';
|
||||||
type AwsClientOptions = { access: AwsAccess; region: string, logger: ILogger };
|
type AwsClientOptions = { access: AwsAccess; region: string, logger: ILogger };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/route-53-domains/
|
||||||
|
*/
|
||||||
export class AwsClient {
|
export class AwsClient {
|
||||||
options: AwsClientOptions;
|
options: AwsClientOptions;
|
||||||
access: AwsAccess;
|
access: AwsAccess;
|
||||||
@@ -77,6 +81,29 @@ export class AwsClient {
|
|||||||
return response.HostedZones;
|
return response.HostedZones;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async route53ListHostedZonesPage(req: PageSearch): Promise<PageRes<DomainRecord>> {
|
||||||
|
const { ListHostedZonesByNameCommand } = await import("@aws-sdk/client-route-53"); // ES Modules import
|
||||||
|
|
||||||
|
const client = await this.route53ClientGet();
|
||||||
|
const input:any = { // ListHostedZonesByNameRequest
|
||||||
|
MaxItems: req.pageSize,
|
||||||
|
};
|
||||||
|
if (req.searchKey) {
|
||||||
|
input.DNSName = req.searchKey;
|
||||||
|
}
|
||||||
|
const command = new ListHostedZonesByNameCommand(input);
|
||||||
|
const response = await this.doRequest(() => client.send(command));
|
||||||
|
let list :any[]= response.HostedZones || [];
|
||||||
|
list = list.map((item: any) => ({
|
||||||
|
id: item.Id.replace('/hostedzone/', ''),
|
||||||
|
domain: item.Name,
|
||||||
|
}));
|
||||||
|
return {
|
||||||
|
total: list.length,
|
||||||
|
list,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
async route53ChangeRecord(req: {
|
async route53ChangeRecord(req: {
|
||||||
hostedZoneId: string, fullRecord: string, type: string, value: string, action: "UPSERT" | "DELETE"
|
hostedZoneId: string, fullRecord: string, type: string, value: string, action: "UPSERT" | "DELETE"
|
||||||
}) {
|
}) {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { AbstractDnsProvider, CreateRecordOptions, IsDnsProvider, RemoveRecordOptions } from '@certd/plugin-cert';
|
import { AbstractDnsProvider, CreateRecordOptions, DomainRecord, IsDnsProvider, RemoveRecordOptions } from '@certd/plugin-cert';
|
||||||
|
|
||||||
import { CloudflareAccess } from './access.js';
|
import { CloudflareAccess } from './access.js';
|
||||||
|
import { Pager, PageRes, PageSearch } from '@certd/pipeline';
|
||||||
|
|
||||||
export type CloudflareRecord = {
|
export type CloudflareRecord = {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -144,6 +145,27 @@ export class CloudflareDnsProvider extends AbstractDnsProvider<CloudflareRecord>
|
|||||||
await this.doRequestApi(url, null, 'delete');
|
await this.doRequestApi(url, null, 'delete');
|
||||||
this.logger.info(`删除域名解析成功:fullRecord=${fullRecord},value=${value}`);
|
this.logger.info(`删除域名解析成功:fullRecord=${fullRecord},value=${value}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getDomainListPage(req: PageSearch): Promise<PageRes<DomainRecord>> {
|
||||||
|
const pager = new Pager(req);
|
||||||
|
|
||||||
|
let url = `https://api.cloudflare.com/client/v4/zones?page=${pager.pageNo}&per_page=${pager.pageSize}`;
|
||||||
|
if (req.searchKey) {
|
||||||
|
url += `&name=${req.searchKey}`;
|
||||||
|
}
|
||||||
|
const ret = await this.doRequestApi(url, null, 'get');
|
||||||
|
|
||||||
|
let list = ret.result || []
|
||||||
|
list = list.map((item: any) => ({
|
||||||
|
id: item.id,
|
||||||
|
domain: item.name,
|
||||||
|
}));
|
||||||
|
const total = ret.result_info.total_count || list.length;
|
||||||
|
return {
|
||||||
|
total,
|
||||||
|
list,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//实例化这个provider,将其自动注册到系统中
|
//实例化这个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 { DnslaAccess } from "./access.js";
|
import { DnslaAccess } from "./access.js";
|
||||||
|
import { Pager, PageRes, PageSearch } from "@certd/pipeline";
|
||||||
|
|
||||||
export type DnslaRecord = {
|
export type DnslaRecord = {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -176,6 +177,24 @@ export class DnslaDnsProvider extends AbstractDnsProvider<DnslaRecord> {
|
|||||||
await this.doRequestApi(url, null, 'delete');
|
await this.doRequestApi(url, null, 'delete');
|
||||||
this.logger.info(`删除域名解析成功:fullRecord=${fullRecord},value=${value}`);
|
this.logger.info(`删除域名解析成功:fullRecord=${fullRecord},value=${value}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getDomainListPage(req: PageSearch): Promise<PageRes<DomainRecord>> {
|
||||||
|
const pager = new Pager(req);
|
||||||
|
const url = `/api/domain?pageIndex=${pager.pageNo}&pageSize=${pager.pageSize}`;
|
||||||
|
const ret = await this.doRequestApi(url, null, 'get');
|
||||||
|
|
||||||
|
|
||||||
|
let list = ret.data.results || []
|
||||||
|
list = list.map((item: any) => ({
|
||||||
|
id: item.id,
|
||||||
|
domain: item.domain,
|
||||||
|
}));
|
||||||
|
const total = ret.data.total || list.length;
|
||||||
|
return {
|
||||||
|
total,
|
||||||
|
list,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//实例化这个provider,将其自动注册到系统中
|
//实例化这个provider,将其自动注册到系统中
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ export class GodaddyAccess extends BaseAccess {
|
|||||||
|
|
||||||
const pager = new Pager(opts);
|
const pager = new Pager(opts);
|
||||||
const req = {
|
const req = {
|
||||||
url :`/v1/domains?limit=${pager.pageSize}`,
|
url :`/v1/domains?limit=${pager.pageSize}&offset=${pager.getOffset()}`,
|
||||||
method: "get",
|
method: "get",
|
||||||
}
|
}
|
||||||
return await this.doRequest(req);
|
return await this.doRequest(req);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { AbstractDnsProvider, CreateRecordOptions, IsDnsProvider, RemoveRecordOptions } from "@certd/plugin-cert";
|
import { AbstractDnsProvider, CreateRecordOptions, DomainRecord, IsDnsProvider, RemoveRecordOptions } from "@certd/plugin-cert";
|
||||||
|
|
||||||
import { GodaddyAccess } from "./access.js";
|
import { GodaddyAccess } from "./access.js";
|
||||||
|
import { Pager, PageRes, PageSearch } from "@certd/pipeline";
|
||||||
|
|
||||||
export type GodaddyRecord = {
|
export type GodaddyRecord = {
|
||||||
domain: string,
|
domain: string,
|
||||||
@@ -84,6 +85,23 @@ export class GodaddyDnsProvider extends AbstractDnsProvider<GodaddyRecord> {
|
|||||||
})
|
})
|
||||||
this.logger.info(`删除域名解析成功:fullRecord=${fullRecord},id=${res}`);
|
this.logger.info(`删除域名解析成功:fullRecord=${fullRecord},id=${res}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getDomainListPage(req: PageSearch): Promise<PageRes<DomainRecord>> {
|
||||||
|
const pager = new Pager(req);
|
||||||
|
|
||||||
|
const ret = await this.access.getDomainList(req)
|
||||||
|
|
||||||
|
let list = ret.zones || []
|
||||||
|
list = list.map((item: any) => ({
|
||||||
|
id: item.domainId,
|
||||||
|
domain: item.domain,
|
||||||
|
}));
|
||||||
|
const total = list.length === pager.pageSize ? list.length+1: list.length
|
||||||
|
return {
|
||||||
|
total,
|
||||||
|
list,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//实例化这个provider,将其自动注册到系统中
|
//实例化这个provider,将其自动注册到系统中
|
||||||
|
|||||||
+23
-1
@@ -1,8 +1,9 @@
|
|||||||
import * as _ from "lodash-es";
|
import * as _ from "lodash-es";
|
||||||
import { AbstractDnsProvider, CreateRecordOptions, IsDnsProvider, RemoveRecordOptions } from "@certd/plugin-cert";
|
import { AbstractDnsProvider, CreateRecordOptions, DomainRecord, IsDnsProvider, RemoveRecordOptions } from "@certd/plugin-cert";
|
||||||
|
|
||||||
import { HuaweiAccess } from "../access/index.js";
|
import { HuaweiAccess } from "../access/index.js";
|
||||||
import { ApiRequestOptions, HuaweiYunClient } from "@certd/lib-huawei";
|
import { ApiRequestOptions, HuaweiYunClient } from "@certd/lib-huawei";
|
||||||
|
import { Pager, PageRes, PageSearch } from "@certd/pipeline";
|
||||||
|
|
||||||
export type SearchRecordOptions = {
|
export type SearchRecordOptions = {
|
||||||
zoneId: string;
|
zoneId: string;
|
||||||
@@ -177,6 +178,27 @@ export class HuaweiDnsProvider extends AbstractDnsProvider {
|
|||||||
this.logger.info("删除域名解析失败,没有找到解析记录", fullRecord, value);
|
this.logger.info("删除域名解析失败,没有找到解析记录", fullRecord, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getDomainListPage(req: PageSearch): Promise<PageRes<DomainRecord>> {
|
||||||
|
const pager = new Pager(req);
|
||||||
|
let url = `${this.dnsEndpoint}/v2/zones?offset=${pager.getOffset()}&limit=${pager.pageSize}`;
|
||||||
|
if (req.searchKey){
|
||||||
|
url += `&name=${req.searchKey}`
|
||||||
|
}
|
||||||
|
const ret = await this.client.request({
|
||||||
|
url,
|
||||||
|
method: "GET"
|
||||||
|
});
|
||||||
|
let list = ret.zones || []
|
||||||
|
list = list.map((item: any) => ({
|
||||||
|
id: item.id,
|
||||||
|
domain: item.name,
|
||||||
|
}));
|
||||||
|
return {
|
||||||
|
total:ret.metadata.total_count || list.length,
|
||||||
|
list,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
new HuaweiDnsProvider();
|
new HuaweiDnsProvider();
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { AbstractDnsProvider, CreateRecordOptions, IsDnsProvider, RemoveRecordOptions } from "@certd/plugin-cert";
|
import { AbstractDnsProvider, CreateRecordOptions, DomainRecord, IsDnsProvider, RemoveRecordOptions } from "@certd/plugin-cert";
|
||||||
import { JDCloudAccess } from "./access.js";
|
import { JDCloudAccess } from "./access.js";
|
||||||
|
import { Pager, PageRes, PageSearch } from "@certd/pipeline";
|
||||||
|
|
||||||
@IsDnsProvider({
|
@IsDnsProvider({
|
||||||
name: "jdcloud",
|
name: "jdcloud",
|
||||||
@@ -92,6 +93,25 @@ export class JDCloudDnsProvider extends AbstractDnsProvider {
|
|||||||
return service;
|
return service;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getDomainListPage(req: PageSearch): Promise<PageRes<DomainRecord>> {
|
||||||
|
const pager = new Pager(req);
|
||||||
|
const service = await this.getJDDomainService();
|
||||||
|
const domainRes = await service.describeDomains({
|
||||||
|
domainName: req.searchKey,
|
||||||
|
pageNumber: pager.pageNo,
|
||||||
|
pageSize: pager.pageSize,
|
||||||
|
})
|
||||||
|
let list = domainRes.result?.dataList || []
|
||||||
|
list = list.map((item: any) => ({
|
||||||
|
id: item.domainId,
|
||||||
|
domain: item.domainName,
|
||||||
|
}));
|
||||||
|
return {
|
||||||
|
total:domainRes.result.totalCount || list.length,
|
||||||
|
list,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
new JDCloudDnsProvider();
|
new JDCloudDnsProvider();
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import { AbstractDnsProvider, CreateRecordOptions, IsDnsProvider, RemoveRecordOptions } from '@certd/plugin-cert';
|
import { AbstractDnsProvider, CreateRecordOptions, DomainRecord, IsDnsProvider, RemoveRecordOptions } from '@certd/plugin-cert';
|
||||||
import qs from 'qs';
|
import qs from 'qs';
|
||||||
import { NamesiloAccess } from './access.js';
|
import { NamesiloAccess } from './access.js';
|
||||||
import { merge } from 'lodash-es';
|
import { merge } from 'lodash-es';
|
||||||
|
import { Pager, PageRes, PageSearch } from '@certd/pipeline';
|
||||||
|
|
||||||
export type NamesiloRecord = {
|
export type NamesiloRecord = {
|
||||||
record_id: string;
|
record_id: string;
|
||||||
@@ -102,6 +103,25 @@ export class NamesiloDnsProvider extends AbstractDnsProvider<NamesiloRecord> {
|
|||||||
});
|
});
|
||||||
this.logger.info(`删除域名解析成功:fullRecord=${fullRecord},value=${value}`);
|
this.logger.info(`删除域名解析成功:fullRecord=${fullRecord},value=${value}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getDomainListPage(req: PageSearch): Promise<PageRes<DomainRecord>> {
|
||||||
|
|
||||||
|
const pager = new Pager(req);
|
||||||
|
const ret =await this.doRequest('/api/listDomains', {
|
||||||
|
key:req.searchKey,
|
||||||
|
page: pager.pageNo,
|
||||||
|
pageSize: pager.pageSize,
|
||||||
|
});
|
||||||
|
// this.logger.info("获取域名列表成功:", ret);
|
||||||
|
const list = ret.domains.map((item: any) => ({
|
||||||
|
id: item.domain,
|
||||||
|
domain: item.domain,
|
||||||
|
}));
|
||||||
|
return {
|
||||||
|
total:ret.pager?.total || list.length,
|
||||||
|
list,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//实例化这个provider,将其自动注册到系统中
|
//实例化这个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 { RainyunAccess } from "./access.js";
|
import { RainyunAccess } from "./access.js";
|
||||||
|
import { Pager, PageRes, PageSearch } from "@certd/pipeline";
|
||||||
|
|
||||||
@IsDnsProvider({
|
@IsDnsProvider({
|
||||||
name: "rainyun",
|
name: "rainyun",
|
||||||
@@ -60,6 +61,25 @@ export class RainyunDnsProvider extends AbstractDnsProvider {
|
|||||||
this.logger.info("删除域名解析成功:", fullRecord, value, ret);
|
this.logger.info("删除域名解析成功:", fullRecord, value, ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getDomainListPage(req: PageSearch): Promise<PageRes<DomainRecord>> {
|
||||||
|
const access: RainyunAccess = this.ctx.access as RainyunAccess;
|
||||||
|
const pager = new Pager(req);
|
||||||
|
const ret = await access.getDomainList({
|
||||||
|
offset: pager.getOffset(),
|
||||||
|
limit: pager.pageSize,
|
||||||
|
query: req.searchKey,
|
||||||
|
})
|
||||||
|
// this.logger.info("获取域名列表成功:", ret);
|
||||||
|
const list = ret.list.map((item: any) => ({
|
||||||
|
id: item.id,
|
||||||
|
domain: item.domain,
|
||||||
|
}));
|
||||||
|
return {
|
||||||
|
total:ret.total || list.length,
|
||||||
|
list,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
new RainyunDnsProvider();
|
new RainyunDnsProvider();
|
||||||
|
|||||||
Reference in New Issue
Block a user