mirror of
https://github.com/certd/certd.git
synced 2026-04-23 19:57:27 +08:00
perf: 支持cloudflare域名
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { IsAccess, AccessInput } from '@certd/pipeline';
|
||||
import { IsAccess, AccessInput, IAccess } from "@certd/pipeline";
|
||||
|
||||
/**
|
||||
* 这个注解将注册一个授权配置
|
||||
@@ -9,7 +9,7 @@ import { IsAccess, AccessInput } from '@certd/pipeline';
|
||||
title: '授权插件示例',
|
||||
desc: '',
|
||||
})
|
||||
export class DemoAccess {
|
||||
export class DemoAccess implements IAccess{
|
||||
/**
|
||||
* 授权属性配置
|
||||
*/
|
||||
|
||||
@@ -1,43 +1,81 @@
|
||||
import { AbstractDnsProvider, CreateRecordOptions, IsDnsProvider, RemoveRecordOptions } from "@certd/plugin-cert";
|
||||
import { Autowire, ILogger } from "@certd/pipeline";
|
||||
import { Autowire, HttpClient, ILogger } from "@certd/pipeline";
|
||||
import { DemoAccess } from "./access";
|
||||
|
||||
// TODO 这里注册一个dnsProvider
|
||||
|
||||
type DemoRecord = {
|
||||
// 这里定义Record记录的数据结构,跟对应云平台接口返回值一样即可,一般是拿到id就行,用于删除txt解析记录,清理申请痕迹
|
||||
// id:string
|
||||
}
|
||||
|
||||
// 这里通过IsDnsProvider注册一个dnsProvider
|
||||
@IsDnsProvider({
|
||||
name: 'demo',
|
||||
title: 'Dns提供商Demo',
|
||||
desc: 'dns provider示例',
|
||||
accessType: 'demo', //这里是对应的access name
|
||||
name: "demo",
|
||||
title: "Dns提供商Demo",
|
||||
desc: "dns provider示例",
|
||||
// 这里是对应的云平台的access类型名称
|
||||
accessType: "demo"
|
||||
})
|
||||
export class DemoDnsProvider extends AbstractDnsProvider {
|
||||
export class DemoDnsProvider extends AbstractDnsProvider<DemoRecord> {
|
||||
// 通过Autowire注入工具对象
|
||||
@Autowire()
|
||||
access!: DemoAccess;
|
||||
@Autowire()
|
||||
logger!: ILogger;
|
||||
http!: HttpClient;
|
||||
|
||||
async onInstance() {
|
||||
const access: any = this.access;
|
||||
this.logger.debug('access', access);
|
||||
// 也可以通过ctx成员变量传递context, 与Autowire效果一样
|
||||
this.http = this.ctx.http;
|
||||
this.logger.debug("access", this.access);
|
||||
//初始化的操作
|
||||
//...
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建dns解析记录,用于验证域名所有权
|
||||
*/
|
||||
async createRecord(options: CreateRecordOptions): Promise<any> {
|
||||
const { fullRecord, value, type,domain } = options;
|
||||
this.logger.info('添加域名解析:', fullRecord, value, type,domain);
|
||||
//TODO 然后调用接口,创建txt类型的dns解析记录
|
||||
// .. 这里调用对应平台的后台接口
|
||||
const access = this.access;
|
||||
this.logger.debug('access', access);
|
||||
/**
|
||||
* options 参数说明
|
||||
* fullRecord: '_acme-challenge.example.com',
|
||||
* value: 一串uuid
|
||||
* type: 'TXT',
|
||||
* domain: 'example.com'
|
||||
*/
|
||||
const { fullRecord, value, type, domain } = options;
|
||||
this.logger.info("添加域名解析:", fullRecord, value, type, domain);
|
||||
|
||||
// 调用创建dns解析记录的对应的云端接口,创建txt类型的dns解析记录
|
||||
// 请根据实际接口情况调用,例如:
|
||||
// const createDnsRecordUrl = "xxx"
|
||||
// const record = this.http.post(createDnsRecordUrl,{
|
||||
// // 授权参数
|
||||
// // 创建dns解析记录的参数
|
||||
// })
|
||||
// //返回本次创建的dns解析记录,这个记录会在删除的时候用到
|
||||
// return record
|
||||
}
|
||||
async removeRecord(options: RemoveRecordOptions): Promise<any> {
|
||||
|
||||
/**
|
||||
* 删除dns解析记录,清理申请痕迹
|
||||
* @param options
|
||||
*/
|
||||
async removeRecord(options: RemoveRecordOptions<DemoRecord>): Promise<void> {
|
||||
const { fullRecord, value, record } = options;
|
||||
this.logger.info('删除域名解析:', fullRecord, value, record);
|
||||
//TODO 这里调用删除txt dns解析记录接口
|
||||
const access = this.access;
|
||||
this.logger.debug('access', access);
|
||||
this.logger.info('删除域名解析成功:', fullRecord, value);
|
||||
this.logger.info("删除域名解析:", fullRecord, value, record);
|
||||
//这里调用删除txt dns解析记录接口
|
||||
//请根据实际接口情况调用,例如:
|
||||
|
||||
// const deleteDnsRecordUrl = "xxx"
|
||||
// const res = this.http.delete(deleteDnsRecordUrl,{
|
||||
// // 授权参数
|
||||
// // 删除dns解析记录的参数
|
||||
// })
|
||||
//
|
||||
|
||||
this.logger.info("删除域名解析成功:", fullRecord, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user