From 9291fa68aa7a88a05c2f888bf3048df36a8fbde3 Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Sun, 28 Sep 2025 23:29:56 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20dns=E8=A7=A3=E6=9E=90=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E9=98=BF=E9=87=8Cesa?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/aliyun/access/aliesa-access.ts | 45 ++++++++ .../plugin-lib/src/aliyun/access/index.ts | 1 + .../dns-provider/aliesa-dns-provider.ts | 105 ++++++++++++++++++ .../plugin-aliyun/dns-provider/index.ts | 1 + 4 files changed, 152 insertions(+) create mode 100644 packages/plugins/plugin-lib/src/aliyun/access/aliesa-access.ts create mode 100644 packages/ui/certd-server/src/plugins/plugin-aliyun/dns-provider/aliesa-dns-provider.ts diff --git a/packages/plugins/plugin-lib/src/aliyun/access/aliesa-access.ts b/packages/plugins/plugin-lib/src/aliyun/access/aliesa-access.ts new file mode 100644 index 00000000..6101069d --- /dev/null +++ b/packages/plugins/plugin-lib/src/aliyun/access/aliesa-access.ts @@ -0,0 +1,45 @@ +import { AccessInput, BaseAccess, IsAccess } from "@certd/pipeline"; + +@IsAccess({ + name: "aliesa", + title: "阿里云ESA授权", + desc: "", + icon: "ant-design:aliyun-outlined", + order: 0, +}) +export class AliesaAccess extends BaseAccess { + @AccessInput({ + title: "阿里云授权", + component: { + name: "access-selector", + vModel: "modelValue", + type: "aliyun", + }, + helper: "请选择阿里云授权", + required: true, + }) + accessId = ""; + + @AccessInput({ + title: "地区", + component: { + name: "a-select", + vModel: "value", + options: [ + { + label: "杭州", + value: "cn-hangzhou", + }, + { + label: "新加坡", + value: "ap-southeast-1", + }, + ], + }, + helper: "请选择ESA地区", + required: true, + }) + region = ""; +} + +new AliesaAccess(); diff --git a/packages/plugins/plugin-lib/src/aliyun/access/index.ts b/packages/plugins/plugin-lib/src/aliyun/access/index.ts index 80693fa3..63e88e50 100644 --- a/packages/plugins/plugin-lib/src/aliyun/access/index.ts +++ b/packages/plugins/plugin-lib/src/aliyun/access/index.ts @@ -1,2 +1,3 @@ export * from "./aliyun-access.js"; export * from "./alioss-access.js"; +export * from "./aliesa-access.js"; diff --git a/packages/ui/certd-server/src/plugins/plugin-aliyun/dns-provider/aliesa-dns-provider.ts b/packages/ui/certd-server/src/plugins/plugin-aliyun/dns-provider/aliesa-dns-provider.ts new file mode 100644 index 00000000..16f4b218 --- /dev/null +++ b/packages/ui/certd-server/src/plugins/plugin-aliyun/dns-provider/aliesa-dns-provider.ts @@ -0,0 +1,105 @@ +import { IAccessService } from '@certd/pipeline'; +import { AbstractDnsProvider, CreateRecordOptions, IsDnsProvider, RemoveRecordOptions } from '@certd/plugin-cert'; + +import { AliesaAccess, AliyunAccess, AliyunClientV2 } from '@certd/plugin-lib'; + +@IsDnsProvider({ + name: 'aliesa', + title: '阿里ESA', + desc: '阿里ESA DNS解析', + accessType: 'aliesa', + icon: 'svg:icon-aliyun', + order: 0, +}) +export class AliesaDnsProvider extends AbstractDnsProvider { + + + client: AliyunClientV2 + async onInstance() { + const access: AliesaAccess = this.ctx.access as AliesaAccess + const accessGetter = await this.ctx.serviceGetter.get("accessService") as IAccessService + const aliAccess = await accessGetter.getById(access.accessId) as AliyunAccess + const endpoint = `esa.${access.region}.aliyuncs.com` + this.client = aliAccess.getClient(endpoint) + } + + + async getSiteItem(domain: string) { + const ret = await this.client.doRequest({ + // 接口名称 + action: "ListSites", + // 接口版本 + version: "2024-09-10", + // 接口协议 + protocol: "HTTPS", + // 接口 HTTP 方法 + method: "GET", + authType: "AK", + style: "RPC", + data: { + query: { + SiteName: domain, + // ["SiteSearchType"] = "exact"; + SiteSearchType: "exact", + AccessType: "NS" + } + } + }) + const list = ret.Sites + if (list?.length === 0) { + throw new Error(`阿里云ESA中不存在此域名站点:${domain},请确认域名已添加到ESA中,且为NS接入方式`); + } + return list[0] + + } + + async createRecord(options: CreateRecordOptions): Promise { + const { fullRecord, value, type, domain } = options; + this.logger.info('添加域名解析:', fullRecord, value, domain); + + + const siteItem = await this.getSiteItem(domain) + const siteId = siteItem.SiteId + + + const res = await this.client.doRequest({ + action: "CreateRecord", + version: "2024-09-10", + method: "POST", + data: { + query: { + SiteId: siteId, + RecordName: fullRecord, + Type: type, + // queries["Ttl"] = 1231311; + Ttl: 100, + Data: JSON.stringify({ Value: value }), + } + } + }) + + this.logger.info('添加域名解析成功:', fullRecord, value, res.RecordId); + return { + RecordId: res.RecordId, + SiteId: siteId, + } + + } + + async removeRecord(options: RemoveRecordOptions): Promise { + const record = options.recordRes; + + await this.client.doRequest({ + action: "DeleteRecord", + version: "2024-09-10", + data: { + query: { + RecordId: record.RecordId, + } + } + }) + this.logger.info('删除域名解析成功:', record.RecordId); + } +} + +new AliesaDnsProvider(); diff --git a/packages/ui/certd-server/src/plugins/plugin-aliyun/dns-provider/index.ts b/packages/ui/certd-server/src/plugins/plugin-aliyun/dns-provider/index.ts index ecb63697..565ab1b9 100644 --- a/packages/ui/certd-server/src/plugins/plugin-aliyun/dns-provider/index.ts +++ b/packages/ui/certd-server/src/plugins/plugin-aliyun/dns-provider/index.ts @@ -1 +1,2 @@ import './aliyun-dns-provider.js'; +import './aliesa-dns-provider.js';