Files
certd/packages/ui/certd-server/src/plugins/plugin-aws/aws-route53-provider.ts
T

65 lines
2.1 KiB
TypeScript
Raw Normal View History

2026-05-31 01:41:33 +08:00
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";
2025-12-25 18:56:27 +08:00
@IsDnsProvider({
2026-05-31 01:41:33 +08:00
name: "aws-route53",
title: "AWS Route53",
desc: "AWS Route53 DNS解析提供商",
accessType: "aws",
icon: "svg:icon-aws",
order: 0,
2025-12-25 18:56:27 +08:00
})
export class AwsRoute53Provider extends AbstractDnsProvider {
client: AwsClient;
async onInstance() {
2026-05-31 01:41:33 +08:00
const access: AwsAccess = this.ctx.access as AwsAccess;
this.client = new AwsClient({ access: access, logger: this.logger, region: access.region || "us-east-1" });
2025-12-25 18:56:27 +08:00
}
async createRecord(options: CreateRecordOptions): Promise<any> {
const { fullRecord, value, type, domain } = options;
2026-05-31 01:41:33 +08:00
this.logger.info("添加域名解析:", fullRecord, value, domain);
2025-12-25 18:56:27 +08:00
// const domain = await this.matchDomain(fullRecord);
2026-05-31 01:41:33 +08:00
const { ZoneId, ZoneName } = await this.client.route53GetHostedZoneId(domain);
2025-12-25 18:56:27 +08:00
this.logger.info(`获取到hostedZoneId:${ZoneId},name:${ZoneName},domain:${domain}`);
2026-05-31 01:41:33 +08:00
2025-12-25 18:56:27 +08:00
await this.client.route53ChangeRecord({
hostedZoneId: ZoneId,
fullRecord: fullRecord,
type: type,
value: value,
2026-05-31 01:41:33 +08:00
action: "UPSERT",
2025-12-25 18:56:27 +08:00
});
return {
hostedZoneId: ZoneId,
2026-05-31 01:41:33 +08:00
};
2025-12-25 18:56:27 +08:00
}
async removeRecord(options: RemoveRecordOptions<any>): Promise<any> {
2026-05-31 01:41:33 +08:00
const { fullRecord, value, type } = options.recordReq;
2025-12-25 18:56:27 +08:00
const record = options.recordRes;
const hostedZoneId = record.hostedZoneId;
2026-05-31 01:41:33 +08:00
try {
2025-12-25 18:56:27 +08:00
await this.client.route53ChangeRecord({
hostedZoneId: hostedZoneId,
fullRecord: fullRecord,
type: type,
value: value,
2026-05-31 01:41:33 +08:00
action: "DELETE",
2025-12-25 18:56:27 +08:00
});
2026-05-31 01:41:33 +08:00
} catch (e) {
this.logger.warn(`删除域名解析失败:${e.message} : ${hostedZoneId} ${fullRecord} ${value} ${type} `);
2025-12-25 18:56:27 +08:00
}
}
async getDomainListPage(req: PageSearch): Promise<PageRes<DomainRecord>> {
return await this.client.route53ListHostedZonesPage(req);
}
2025-12-25 18:56:27 +08:00
}
new AwsRoute53Provider();