mirror of
https://github.com/certd/certd.git
synced 2026-04-24 04:17:25 +08:00
chore:
This commit is contained in:
@@ -4,6 +4,7 @@ import * as api from "./api";
|
||||
// @ts-ignore
|
||||
import _ from "lodash-es";
|
||||
import { toRef } from "vue";
|
||||
import { useReference } from "/@/use/use-refrence";
|
||||
|
||||
export function getCommonColumnDefine(crudExpose: any, typeRef: any) {
|
||||
const AccessTypeDictRef = dict({
|
||||
@@ -32,19 +33,10 @@ export function getCommonColumnDefine(crudExpose: any, typeRef: any) {
|
||||
...value,
|
||||
key
|
||||
};
|
||||
let column = _.merge({ title: key }, defaultPluginConfig, field);
|
||||
const column = _.merge({ title: key }, defaultPluginConfig, field);
|
||||
|
||||
//eval
|
||||
if (column.mergeScript) {
|
||||
const ctx = {
|
||||
compute
|
||||
};
|
||||
const script = column.mergeScript;
|
||||
delete column.mergeScript;
|
||||
const func = new Function("ctx", script);
|
||||
const merged = func(ctx);
|
||||
column = _.merge(column, merged);
|
||||
}
|
||||
useReference(column);
|
||||
|
||||
//设置默认值
|
||||
if (column.value != null && _.get(form, key) == null) {
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
"@alicloud/pop-core": "^1.7.10",
|
||||
"@certd/acme-client": "^1.24.4",
|
||||
"@certd/lib-huawei": "^1.24.3",
|
||||
"@certd/lib-jdcloud": "^1.24.4",
|
||||
"@certd/lib-k8s": "^1.24.4",
|
||||
"@certd/midway-flyway-js": "^1.24.4",
|
||||
"@certd/pipeline": "^1.24.4",
|
||||
@@ -62,6 +63,7 @@
|
||||
"md5": "^2.3.0",
|
||||
"mwtsc": "^1.4.0",
|
||||
"nanoid": "^4.0.0",
|
||||
"node-fetch": "^3.3.2",
|
||||
"nodemailer": "^6.9.3",
|
||||
"pg": "^8.12.0",
|
||||
"qiniu": "^7.12.0",
|
||||
@@ -72,7 +74,8 @@
|
||||
"svg-captcha": "^1.4.0",
|
||||
"syno": "^2.2.0",
|
||||
"tencentcloud-sdk-nodejs": "^4.0.44",
|
||||
"typeorm": "^0.3.20"
|
||||
"typeorm": "^0.3.20",
|
||||
"uuid": "^8.3.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@midwayjs/mock": "^3.16.4",
|
||||
|
||||
@@ -9,3 +9,4 @@ export * from './plugin-other/index.js';
|
||||
export * from './plugin-west/index.js';
|
||||
export * from './plugin-doge/index.js';
|
||||
export * from './plugin-qiniu/index.js';
|
||||
export * from './plugin-jdcloud/index.js';
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import { AccessInput, IsAccess } from '@certd/pipeline';
|
||||
|
||||
/**
|
||||
* 这个注解将注册一个授权配置
|
||||
* 在certd的后台管理系统中,用户可以选择添加此类型的授权
|
||||
*/
|
||||
@IsAccess({
|
||||
name: 'dynadot',
|
||||
title: 'dynadot授权',
|
||||
desc: '目前设置dns解析会覆盖已有的解析配置,慎用',
|
||||
})
|
||||
export class DynadotAccess {
|
||||
/**
|
||||
* 授权属性配置
|
||||
*/
|
||||
@AccessInput({
|
||||
title: 'API Production Key',
|
||||
component: {
|
||||
placeholder: '授权key',
|
||||
},
|
||||
helper: '前往 [Dynadot API](https://www.dynadot.com/account/domain/setting/api.html) 获取 API Production Key',
|
||||
required: true,
|
||||
encrypt: true,
|
||||
})
|
||||
apiProductionKey = '';
|
||||
}
|
||||
|
||||
new DynadotAccess();
|
||||
@@ -0,0 +1,85 @@
|
||||
import { AbstractDnsProvider, CreateRecordOptions, IsDnsProvider, RemoveRecordOptions } from '@certd/plugin-cert';
|
||||
import { Autowire, ILogger } from '@certd/pipeline';
|
||||
import { DynadotAccess } from './access.js';
|
||||
import querystring from 'querystring';
|
||||
|
||||
// 这里通过IsDnsProvider注册一个dnsProvider
|
||||
@IsDnsProvider({
|
||||
name: 'dynadot',
|
||||
title: 'dynadot',
|
||||
desc: 'dynadot dns provider',
|
||||
// 这里是对应的 cloudflare的access类型名称
|
||||
accessType: 'dynadot',
|
||||
})
|
||||
export class DynadotDnsProvider extends AbstractDnsProvider {
|
||||
// 通过Autowire传递context
|
||||
@Autowire()
|
||||
logger!: ILogger;
|
||||
access!: DynadotAccess;
|
||||
async onInstance() {
|
||||
this.access = this.ctx.access as DynadotAccess;
|
||||
}
|
||||
|
||||
private async doRequest(command: string, query: any) {
|
||||
const baseUrl = 'https://api.dynadot.com/api3.json?key=' + this.access.apiProductionKey;
|
||||
const qs = querystring.stringify(query);
|
||||
const url = `${baseUrl}&command=${command}&${qs}`;
|
||||
const res = await this.ctx.http.request<any, any>({
|
||||
url,
|
||||
method: 'get',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
/*
|
||||
"SetDnsResponse": {
|
||||
"ResponseCode": 0,
|
||||
"Status": "success"
|
||||
}
|
||||
*/
|
||||
for (const resKey in res) {
|
||||
if (res[resKey].ResponseCode != null && res[resKey].ResponseCode !== 0) {
|
||||
throw new Error(`请求失败:${res[resKey].Status}`);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建dns解析记录,用于验证域名所有权
|
||||
*/
|
||||
async createRecord(options: CreateRecordOptions) {
|
||||
/**
|
||||
* fullRecord: '_acme-challenge.test.example.com',
|
||||
* value: 一串uuid
|
||||
* type: 'TXT',
|
||||
* domain: 'example.com'
|
||||
*/
|
||||
const { fullRecord, value, type, domain } = options;
|
||||
this.logger.info('添加域名解析:', fullRecord, value, type, domain);
|
||||
|
||||
const prefix = fullRecord.replace(`.${domain}`, '');
|
||||
// 给domain下创建txt类型的dns解析记录,fullRecord
|
||||
const res = await this.doRequest('set_dns2', {
|
||||
domain: domain,
|
||||
subdomain0: prefix,
|
||||
sub_record_type0: 'TXT',
|
||||
sub_record0 : value,
|
||||
});
|
||||
this.logger.info(`添加域名解析成功:fullRecord=${fullRecord},value=${value}`);
|
||||
this.logger.info(`请求结果:${JSON.stringify(res)}`);
|
||||
|
||||
//本接口需要返回本次创建的dns解析记录,这个记录会在删除的时候用到
|
||||
return {};
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除dns解析记录,清理申请痕迹
|
||||
* @param options
|
||||
*/
|
||||
async removeRecord(options: RemoveRecordOptions<any>): Promise<void> {}
|
||||
}
|
||||
|
||||
//实例化这个provider,将其自动注册到系统中
|
||||
new DynadotDnsProvider();
|
||||
@@ -0,0 +1,3 @@
|
||||
export * from './dns-provider.js';
|
||||
export * from './plugins/index.js';
|
||||
export * from './access.js';
|
||||
@@ -0,0 +1,39 @@
|
||||
import { AccessInput, IsAccess } from '@certd/pipeline';
|
||||
|
||||
/**
|
||||
* 这个注解将注册一个授权配置
|
||||
* 在certd的后台管理系统中,用户可以选择添加此类型的授权
|
||||
*/
|
||||
@IsAccess({
|
||||
name: 'jdcloud',
|
||||
title: '京东云授权',
|
||||
desc: '目前设置dns解析会覆盖已有的解析配置,慎用',
|
||||
})
|
||||
export class JDCloudAccess {
|
||||
/**
|
||||
* 授权属性配置
|
||||
*/
|
||||
@AccessInput({
|
||||
title: 'AccessKeyId',
|
||||
component: {
|
||||
placeholder: 'AK',
|
||||
},
|
||||
helper: '前往 [AccessKey管理](https://uc.jdcloud.com/account/accesskey) 获取 API Production Key',
|
||||
required: true,
|
||||
encrypt: true,
|
||||
})
|
||||
accessKeyId = '';
|
||||
|
||||
@AccessInput({
|
||||
title: 'AccessKeySecret',
|
||||
component: {
|
||||
placeholder: 'SK',
|
||||
},
|
||||
helper: 'SK',
|
||||
required: true,
|
||||
encrypt: true,
|
||||
})
|
||||
accessKeySecret = '';
|
||||
}
|
||||
|
||||
new JDCloudAccess();
|
||||
@@ -0,0 +1,111 @@
|
||||
import { AbstractDnsProvider, CreateRecordOptions, IsDnsProvider, RemoveRecordOptions } from '@certd/plugin-cert';
|
||||
import { Autowire, ILogger } from '@certd/pipeline';
|
||||
import { JDCloudAccess } from './access.js';
|
||||
function promisfy(func: any) {
|
||||
return (params: any, regionId: string) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
func(params, regionId, (err, result) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
resolve(result);
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
// 这里通过IsDnsProvider注册一个dnsProvider
|
||||
@IsDnsProvider({
|
||||
name: 'jdcloud',
|
||||
title: '京东云',
|
||||
desc: '京东云 dns provider',
|
||||
// 这里是对应的 cloudflare的access类型名称
|
||||
accessType: 'jdcloud',
|
||||
})
|
||||
export class JDCloudDnsProvider extends AbstractDnsProvider {
|
||||
// 通过Autowire传递context
|
||||
@Autowire()
|
||||
logger!: ILogger;
|
||||
access!: JDCloudAccess;
|
||||
service!: any;
|
||||
regionId: string;
|
||||
async onInstance() {
|
||||
this.access = this.ctx.access as JDCloudAccess;
|
||||
const { DomainService } = await import('@certd/lib-jdcloud');
|
||||
// @ts-ignore
|
||||
this.regionId = 'cn-north-1';
|
||||
this.service = new DomainService({
|
||||
credentials: {
|
||||
accessKeyId: this.access.accessKeyId,
|
||||
secretAccessKey: this.access.accessKeySecret,
|
||||
},
|
||||
regionId: this.regionId,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建dns解析记录,用于验证域名所有权
|
||||
*/
|
||||
async createRecord(options: CreateRecordOptions) {
|
||||
/**
|
||||
* fullRecord: '_acme-challenge.test.example.com',
|
||||
* value: 一串uuid
|
||||
* type: 'TXT',
|
||||
* domain: 'example.com'
|
||||
*/
|
||||
const { fullRecord, value, type, domain } = options;
|
||||
this.logger.info('添加域名解析:', fullRecord, value, type, domain);
|
||||
|
||||
const describeDomains = promisfy(this.service.describeDomains);
|
||||
|
||||
const res: any = await describeDomains({ domainName: domain, pageNumber: 1, pageSize: 10 }, this.regionId);
|
||||
|
||||
if (res.dataList.length === 0) {
|
||||
throw new Error('账号下找不到域名:' + domain);
|
||||
}
|
||||
const domainId = res.dataList[0].id;
|
||||
|
||||
//开始创建解析记录
|
||||
const createResourceRecord = promisfy(this.service.createResourceRecord);
|
||||
const res2: any = await createResourceRecord(
|
||||
{
|
||||
domainId,
|
||||
req: {
|
||||
hostRecord: fullRecord,
|
||||
hostValue: value,
|
||||
type: 'TXT',
|
||||
},
|
||||
},
|
||||
this.regionId
|
||||
);
|
||||
|
||||
const recordId = res2.dataList[0].id;
|
||||
|
||||
this.logger.info(`添加域名解析成功:fullRecord=${fullRecord},value=${value}`);
|
||||
this.logger.info(`请求结果:recordId:${recordId}`);
|
||||
|
||||
//本接口需要返回本次创建的dns解析记录,这个记录会在删除的时候用到
|
||||
return { id: recordId, domainId };
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除dns解析记录,清理申请痕迹
|
||||
* @param opts
|
||||
*/
|
||||
async removeRecord(opts: RemoveRecordOptions<any>): Promise<void> {
|
||||
const { record } = opts;
|
||||
const deleteResourceRecord = promisfy(this.service.deleteResourceRecord);
|
||||
const res = await deleteResourceRecord(
|
||||
{
|
||||
domainId: record.domainId,
|
||||
resourceRecordId: record.id,
|
||||
},
|
||||
this.regionId
|
||||
);
|
||||
this.logger.info(`删除dns解析记录成功:${JSON.stringify(res)}`);
|
||||
}
|
||||
}
|
||||
|
||||
//实例化这个provider,将其自动注册到系统中
|
||||
new JDCloudDnsProvider();
|
||||
@@ -0,0 +1,3 @@
|
||||
export * from './dns-provider.js';
|
||||
export * from './plugins/index.js';
|
||||
export * from './access.js';
|
||||
Reference in New Issue
Block a user