mirror of
https://github.com/certd/certd.git
synced 2026-04-23 19:57:27 +08:00
perf: dns支持火山引擎
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
import { AbstractDnsProvider, CreateRecordOptions, IsDnsProvider, RemoveRecordOptions } from "@certd/plugin-cert";
|
||||
import { Autowire } from "@certd/pipeline";
|
||||
|
||||
import { VolcengineClient } from "./client.js";
|
||||
import { VolcengineAccess } from "./access.js";
|
||||
|
||||
@IsDnsProvider({
|
||||
name: "volcengine",
|
||||
title: "火山引擎",
|
||||
desc: "火山引擎DNS解析提供商",
|
||||
accessType: "volcengine",
|
||||
icon: "svg:icon-volcengine"
|
||||
})
|
||||
export class VolcengineDnsProvider extends AbstractDnsProvider {
|
||||
client: VolcengineClient;
|
||||
@Autowire()
|
||||
access!: VolcengineAccess;
|
||||
|
||||
|
||||
async onInstance() {
|
||||
this.client = new VolcengineClient({
|
||||
access: this.access,
|
||||
logger: this.logger,
|
||||
http: this.http
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param domain
|
||||
*/
|
||||
async getDomain(domain: string) {
|
||||
const res = await this.client.findDomain(domain)
|
||||
|
||||
if (res.Result.Zones && res.Result.Zones.length > 0) {
|
||||
return res.Result.Zones[0];
|
||||
}
|
||||
throw new Error(`域名${domain}不存在`);
|
||||
}
|
||||
|
||||
|
||||
async createRecord(options: CreateRecordOptions): Promise<any> {
|
||||
const { fullRecord, hostRecord, value, type, domain } = options;
|
||||
this.logger.info("添加域名解析:", fullRecord, value, domain);
|
||||
|
||||
const domainInfo = await this.getDomain(domain);
|
||||
const ZID = domainInfo.ZID;
|
||||
|
||||
const body = {
|
||||
ZID,
|
||||
"Host": hostRecord,
|
||||
"Type": type,
|
||||
"Value": value
|
||||
};
|
||||
|
||||
const res = await this.client.doRequest({
|
||||
method: "POST",
|
||||
service: "dns",
|
||||
region: "cn-beijing",
|
||||
query: {
|
||||
Action: "CreateRecord",
|
||||
Version: "2018-08-01"
|
||||
},
|
||||
body
|
||||
});
|
||||
|
||||
return {
|
||||
RecordID: res.Result.RecordID,
|
||||
ZID: ZID
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
async removeRecord(options: RemoveRecordOptions<any>): Promise<any> {
|
||||
const record = options.recordRes;
|
||||
|
||||
const body = {
|
||||
RecordID: record.RecordID
|
||||
};
|
||||
|
||||
await this.client.doRequest({
|
||||
method: "POST",
|
||||
service: "dns",
|
||||
region: "cn-beijing",
|
||||
query: {
|
||||
Action: "DeleteRecord",
|
||||
Version: "2018-08-01"
|
||||
},
|
||||
body
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
new VolcengineDnsProvider();
|
||||
Reference in New Issue
Block a user