mirror of https://github.com/certd/certd
chore: CF准备开始
parent
0dd4953197
commit
ebf2a820cc
|
@ -0,0 +1,27 @@
|
||||||
|
import { IsAccess, AccessInput } from '@certd/pipeline';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 这个注解将注册一个授权配置
|
||||||
|
* 在certd的后台管理系统中,用户可以选择添加此类型的授权
|
||||||
|
*/
|
||||||
|
@IsAccess({
|
||||||
|
name: 'cloudflare',
|
||||||
|
title: '授权插件示例',
|
||||||
|
desc: '',
|
||||||
|
})
|
||||||
|
export class CloudflareAccess {
|
||||||
|
/**
|
||||||
|
* 授权属性配置
|
||||||
|
*/
|
||||||
|
@AccessInput({
|
||||||
|
title: 'API Token',
|
||||||
|
component: {
|
||||||
|
placeholder: 'api token',
|
||||||
|
},
|
||||||
|
helper: '前往 https://dash.cloudflare.com/profile/api-tokens 获取token',
|
||||||
|
required: true,
|
||||||
|
})
|
||||||
|
apiToken = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
new CloudflareAccess();
|
|
@ -0,0 +1,78 @@
|
||||||
|
import _ from 'lodash';
|
||||||
|
import {
|
||||||
|
CreateRecordOptions,
|
||||||
|
IDnsProvider,
|
||||||
|
IsDnsProvider,
|
||||||
|
RemoveRecordOptions,
|
||||||
|
} from '@certd/plugin-cert';
|
||||||
|
import { Autowire, ILogger } from '@certd/pipeline';
|
||||||
|
import { CloudflareAccess } from './access';
|
||||||
|
|
||||||
|
// TODO 这里注册一个dnsProvider
|
||||||
|
@IsDnsProvider({
|
||||||
|
name: 'cloudflare',
|
||||||
|
title: 'dns提供商cloudflare',
|
||||||
|
desc: 'cloudflare dns provider示例',
|
||||||
|
accessType: 'cloudflare',
|
||||||
|
})
|
||||||
|
export class CloudflareDnsProvider implements IDnsProvider {
|
||||||
|
@Autowire()
|
||||||
|
access!: CloudflareAccess;
|
||||||
|
@Autowire()
|
||||||
|
logger!: ILogger;
|
||||||
|
|
||||||
|
async onInstance() {
|
||||||
|
const access: any = this.access;
|
||||||
|
this.logger.debug('access', access);
|
||||||
|
//初始化的操作
|
||||||
|
//...
|
||||||
|
}
|
||||||
|
|
||||||
|
async getDomainList(): Promise<any[]> {
|
||||||
|
// TODO 这里你要实现一个获取域名列表的方法
|
||||||
|
const access = this.access;
|
||||||
|
this.logger.debug('access', access);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
async matchDomain(dnsRecord: string): Promise<any> {
|
||||||
|
const domainList = await this.getDomainList();
|
||||||
|
let domainRecord = null;
|
||||||
|
for (const item of domainList) {
|
||||||
|
//TODO 根据域名去匹配账户中是否有该域名, 这里不一定是item.name 具体要看你要实现的平台的接口而定
|
||||||
|
if (_.endsWith(dnsRecord + '.', item.name)) {
|
||||||
|
domainRecord = item;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!domainRecord) {
|
||||||
|
this.logger.info('账户中域名列表:', domainList);
|
||||||
|
this.logger.error('找不到域名,请确认账户中是否真的有此域名');
|
||||||
|
throw new Error('can not find Domain:' + dnsRecord);
|
||||||
|
}
|
||||||
|
return domainRecord;
|
||||||
|
}
|
||||||
|
|
||||||
|
async createRecord(options: CreateRecordOptions): Promise<any> {
|
||||||
|
const { fullRecord, value, type } = options;
|
||||||
|
this.logger.info('添加域名解析:', fullRecord, value, type);
|
||||||
|
//先确定账户中是否有该域名
|
||||||
|
const domainRecord = await this.matchDomain(fullRecord);
|
||||||
|
this.logger.debug('matchDomain:', domainRecord);
|
||||||
|
//TODO 然后调用接口,创建txt类型的dns解析记录
|
||||||
|
// .. 这里调用对应平台的后台接口
|
||||||
|
const access = this.access;
|
||||||
|
this.logger.debug('access', access);
|
||||||
|
}
|
||||||
|
async removeRecord(options: RemoveRecordOptions): Promise<any> {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO 实例化这个provider,将其自动注册到系统中
|
||||||
|
new CloudflareDnsProvider();
|
|
@ -0,0 +1,3 @@
|
||||||
|
export * from './dns-provider';
|
||||||
|
export * from './plugins';
|
||||||
|
export * from './access';
|
|
@ -0,0 +1 @@
|
||||||
|
export * from './plugin-deploy-to-cdn';
|
|
@ -0,0 +1,100 @@
|
||||||
|
import {
|
||||||
|
AbstractTaskPlugin,
|
||||||
|
IAccessService,
|
||||||
|
ILogger,
|
||||||
|
IsTaskPlugin,
|
||||||
|
RunStrategy,
|
||||||
|
TaskInput,
|
||||||
|
} from '@certd/pipeline';
|
||||||
|
import { CertInfo, CertReader } from '@certd/plugin-cert';
|
||||||
|
|
||||||
|
@IsTaskPlugin({
|
||||||
|
name: 'CloudflareDeployToCDN',
|
||||||
|
title: '部署证书到CF CDN',
|
||||||
|
default: {
|
||||||
|
strategy: {
|
||||||
|
runStrategy: RunStrategy.SkipWhenSucceed,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
export class CloudflareDeployToCDNPlugin extends AbstractTaskPlugin {
|
||||||
|
//测试参数
|
||||||
|
@TaskInput({
|
||||||
|
title: '属性示例',
|
||||||
|
component: {
|
||||||
|
//前端组件配置,具体配置见组件文档 https://www.antdv.com/components/input-cn
|
||||||
|
name: 'a-input',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
text!: string;
|
||||||
|
|
||||||
|
//测试参数
|
||||||
|
@TaskInput({
|
||||||
|
title: '选择框',
|
||||||
|
component: {
|
||||||
|
//前端组件配置,具体配置见组件文档 https://www.antdv.com/components/select-cn
|
||||||
|
name: 'a-select',
|
||||||
|
options: [
|
||||||
|
{ value: '1', label: '选项1' },
|
||||||
|
{ value: '2', label: '选项2' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
select!: string;
|
||||||
|
|
||||||
|
//测试参数
|
||||||
|
@TaskInput({
|
||||||
|
title: 'switch',
|
||||||
|
component: {
|
||||||
|
//前端组件配置,具体配置见组件文档 https://www.antdv.com/components/switch-cn
|
||||||
|
name: 'a-switch',
|
||||||
|
vModel: 'checked',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
switch!: boolean;
|
||||||
|
//证书选择,此项必须要有
|
||||||
|
@TaskInput({
|
||||||
|
title: '域名证书',
|
||||||
|
helper: '请选择前置任务输出的域名证书',
|
||||||
|
component: {
|
||||||
|
name: 'pi-output-selector',
|
||||||
|
},
|
||||||
|
required: true,
|
||||||
|
})
|
||||||
|
cert!: CertInfo;
|
||||||
|
|
||||||
|
//授权选择框
|
||||||
|
@TaskInput({
|
||||||
|
title: 'demo授权',
|
||||||
|
helper: 'demoAccess授权',
|
||||||
|
component: {
|
||||||
|
name: 'pi-access-selector',
|
||||||
|
type: 'plugins',
|
||||||
|
},
|
||||||
|
rules: [{ required: true, message: '此项必填' }],
|
||||||
|
})
|
||||||
|
accessId!: string;
|
||||||
|
|
||||||
|
accessService!: IAccessService;
|
||||||
|
logger!: ILogger;
|
||||||
|
|
||||||
|
async onInstance() {
|
||||||
|
this.accessService = this.ctx.accessService;
|
||||||
|
this.logger = this.ctx.logger;
|
||||||
|
}
|
||||||
|
async execute(): Promise<void> {
|
||||||
|
const { select, text, cert, accessId } = this;
|
||||||
|
const certReader = new CertReader(cert);
|
||||||
|
const access = await this.accessService.getById(accessId);
|
||||||
|
this.logger.debug('access', access);
|
||||||
|
this.logger.debug('certReader', certReader);
|
||||||
|
this.logger.info('DemoTestPlugin execute');
|
||||||
|
this.logger.info('text:', text);
|
||||||
|
this.logger.info('select:', select);
|
||||||
|
this.logger.info('switch:', this.switch);
|
||||||
|
this.logger.info('授权id:', accessId);
|
||||||
|
//TODO 这里实现你要部署的执行方法
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//TODO 这里实例化插件,进行注册
|
||||||
|
new CloudflareDeployToCDNPlugin();
|
|
@ -5,7 +5,7 @@ import { IsAccess, AccessInput } from '@certd/pipeline';
|
||||||
* 在certd的后台管理系统中,用户可以选择添加此类型的授权
|
* 在certd的后台管理系统中,用户可以选择添加此类型的授权
|
||||||
*/
|
*/
|
||||||
@IsAccess({
|
@IsAccess({
|
||||||
name: 'plugins',
|
name: 'demo',
|
||||||
title: '授权插件示例',
|
title: '授权插件示例',
|
||||||
desc: '',
|
desc: '',
|
||||||
})
|
})
|
||||||
|
|
|
@ -10,10 +10,10 @@ import { DemoAccess } from './access';
|
||||||
|
|
||||||
// TODO 这里注册一个dnsProvider
|
// TODO 这里注册一个dnsProvider
|
||||||
@IsDnsProvider({
|
@IsDnsProvider({
|
||||||
name: 'plugins',
|
name: 'demo',
|
||||||
title: 'Dns提供商Demo',
|
title: 'Dns提供商Demo',
|
||||||
desc: 'plugins dns provider示例',
|
desc: 'dns provider示例',
|
||||||
accessType: 'plugins',
|
accessType: 'demo', //这里是对应的access name
|
||||||
})
|
})
|
||||||
export class DemoDnsProvider implements IDnsProvider {
|
export class DemoDnsProvider implements IDnsProvider {
|
||||||
@Autowire()
|
@Autowire()
|
||||||
|
|
Loading…
Reference in New Issue