mirror of
https://github.com/certd/certd.git
synced 2026-04-23 19:57:27 +08:00
perf: 所有的dnsprovider 支持导入域名列表
This commit is contained in:
@@ -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 { AwsAccess } from './access.js';
|
||||
import { PageRes, PageSearch } from '@certd/pipeline';
|
||||
|
||||
|
||||
@IsDnsProvider({
|
||||
@@ -57,6 +58,10 @@ export class AwsRoute53Provider extends AbstractDnsProvider {
|
||||
this.logger.warn(`删除域名解析失败:${e.message} : ${hostedZoneId} ${fullRecord} ${value} ${type} `, );
|
||||
}
|
||||
}
|
||||
|
||||
async getDomainListPage(req: PageSearch): Promise<PageRes<DomainRecord>> {
|
||||
return await this.client.route53ListHostedZonesPage(req);
|
||||
}
|
||||
}
|
||||
|
||||
new AwsRoute53Provider();
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
// 导入所需的 SDK 模块
|
||||
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 { PageRes, PageSearch } from '@certd/pipeline';
|
||||
type AwsClientOptions = { access: AwsAccess; region: string, logger: ILogger };
|
||||
|
||||
/**
|
||||
* https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/route-53-domains/
|
||||
*/
|
||||
export class AwsClient {
|
||||
options: AwsClientOptions;
|
||||
access: AwsAccess;
|
||||
@@ -77,6 +81,29 @@ export class AwsClient {
|
||||
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: {
|
||||
hostedZoneId: string, fullRecord: string, type: string, value: string, action: "UPSERT" | "DELETE"
|
||||
}) {
|
||||
|
||||
Reference in New Issue
Block a user