mirror of
https://github.com/certd/certd.git
synced 2026-04-24 04:17:25 +08:00
perf: 支持京东云dns申请证书
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import {AccessInput, BaseAccess, IsAccess} from '@certd/pipeline';
|
||||
|
||||
/**
|
||||
* 这个注解将注册一个授权配置
|
||||
* 在certd的后台管理系统中,用户可以选择添加此类型的授权
|
||||
*/
|
||||
@IsAccess({
|
||||
name: 'jdcloud',
|
||||
title: '京东云',
|
||||
desc: '',
|
||||
icon: 'svg:icon-jdcloud',
|
||||
})
|
||||
export class JDCloudAccess extends BaseAccess {
|
||||
|
||||
@AccessInput({
|
||||
title: 'AccessKeyID',
|
||||
component: {
|
||||
placeholder: 'AccessKeyID',
|
||||
},
|
||||
helper:"[获取密钥](https://uc.jdcloud.com/account/accesskey)",
|
||||
required: true,
|
||||
})
|
||||
accessKeyId = '';
|
||||
@AccessInput({
|
||||
title: 'SecretAccessKey',
|
||||
component: {
|
||||
placeholder: 'SecretAccessKey',
|
||||
},
|
||||
required: true,
|
||||
encrypt: true,
|
||||
})
|
||||
secretAccessKey = '';
|
||||
|
||||
}
|
||||
|
||||
new JDCloudAccess();
|
||||
@@ -0,0 +1,97 @@
|
||||
import { AbstractDnsProvider, CreateRecordOptions, IsDnsProvider, RemoveRecordOptions } from "@certd/plugin-cert";
|
||||
import { Autowire } from "@certd/pipeline";
|
||||
import { JDCloudAccess } from "./access.js";
|
||||
|
||||
@IsDnsProvider({
|
||||
name: "jdcloud",
|
||||
title: "京东云",
|
||||
desc: "京东云DNS解析提供商",
|
||||
accessType: "jdcloud",
|
||||
icon: "svg:icon-jdcloud"
|
||||
})
|
||||
export class JDCloudDnsProvider extends AbstractDnsProvider {
|
||||
@Autowire()
|
||||
access!: JDCloudAccess;
|
||||
|
||||
|
||||
async onInstance() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
async createRecord(options: CreateRecordOptions): Promise<any> {
|
||||
const { fullRecord, hostRecord, value, type, domain } = options;
|
||||
this.logger.info("添加域名解析:", fullRecord, value, domain);
|
||||
|
||||
const service = await this.getJDDomainService();
|
||||
|
||||
const domainRes = await service.describeDomains({
|
||||
domainName: domain,
|
||||
pageNumber: 1,
|
||||
pageSize: 10
|
||||
})
|
||||
if (!domainRes.result?.dataList?.length) {
|
||||
throw new Error(`域名${domain}在此京东云账号中不存在`)
|
||||
}
|
||||
|
||||
const domainId = domainRes.result.dataList[0].id
|
||||
this.logger.info("域名ID:", domainId)
|
||||
/**
|
||||
* hostRecord String True 主机记录
|
||||
* hostValue String True 解析记录的值
|
||||
* jcloudRes Boolean False 是否是京东云资源
|
||||
* mxPriority Integer False 优先级,只存在于MX, SRV解析记录类型
|
||||
* port Integer False 端口,只存在于SRV解析记录类型
|
||||
* ttl Integer True 解析记录的生存时间,单位:秒
|
||||
* type String True 解析的类型,请参考解析记录类型详解
|
||||
* weight Integer False 解析记录的权重,目前支持权重的有:A/AAAA/CNAME/JNAME,A/AAAA权重范围:0-100、CNAME/JNAME权重范围:1-100。
|
||||
* viewValue Integer True 解析线路的ID,请调用describeViewTree接口获取基础解
|
||||
*/
|
||||
try{
|
||||
const res = await service.createResourceRecord({
|
||||
domainId: domainId,
|
||||
req:{
|
||||
hostRecord: hostRecord,
|
||||
hostValue: value,
|
||||
type: type,
|
||||
ttl: 100,
|
||||
}
|
||||
})
|
||||
return {
|
||||
recordId: res.result.dataList[0].id,
|
||||
domainId: domainId
|
||||
};
|
||||
}catch (e) {
|
||||
this.logger.error(e)
|
||||
throw e
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
async removeRecord(options: RemoveRecordOptions<any>): Promise<any> {
|
||||
const record = options.recordRes;
|
||||
|
||||
const service = await this.getJDDomainService();
|
||||
await service.deleteResourceRecord({
|
||||
domainId: record.domainId,
|
||||
resourceRecordId: record.recordId
|
||||
})
|
||||
}
|
||||
|
||||
private async getJDDomainService() {
|
||||
const {JDDomainService} = await import("@certd/jdcloud")
|
||||
const service = new JDDomainService({
|
||||
credentials: {
|
||||
accessKeyId: this.access.accessKeyId,
|
||||
secretAccessKey: this.access.secretAccessKey
|
||||
},
|
||||
regionId: "cn-north-1" //地域信息,某个api调用可以单独传参regionId,如果不传则会使用此配置中的regionId
|
||||
});
|
||||
return service;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
new JDCloudDnsProvider();
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './access.js';
|
||||
export * from './dns-provider.js';
|
||||
Reference in New Issue
Block a user