mirror of
https://github.com/certd/certd.git
synced 2026-04-24 04:17:25 +08:00
feat: midway注解方式编写插件
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import { Registrable } from "@certd/pipeline";
|
||||
|
||||
export type DnsProviderDefine = Registrable & {
|
||||
accessType: string;
|
||||
autowire?: {
|
||||
[key: string]: any;
|
||||
};
|
||||
};
|
||||
|
||||
export type CreateRecordOptions = {
|
||||
fullRecord: string;
|
||||
type: string;
|
||||
value: any;
|
||||
};
|
||||
export type RemoveRecordOptions = CreateRecordOptions & {
|
||||
record: any;
|
||||
};
|
||||
|
||||
export interface IDnsProvider {
|
||||
onInit(): Promise<void>;
|
||||
createRecord(options: CreateRecordOptions): Promise<any>;
|
||||
removeRecord(options: RemoveRecordOptions): Promise<any>;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// src/decorator/memoryCache.decorator.ts
|
||||
import { dnsProviderRegistry } from "./registry";
|
||||
import { DnsProviderDefine } from "./api";
|
||||
import { Decorator, AUTOWIRE_KEY } from "@certd/pipeline";
|
||||
import _ from "lodash";
|
||||
|
||||
// 提供一个唯一 key
|
||||
export const DNS_PROVIDER_CLASS_KEY = "pipeline:dns-provider";
|
||||
|
||||
export function IsDnsProvider(define: DnsProviderDefine): ClassDecorator {
|
||||
return (target: any) => {
|
||||
target = Decorator.target(target);
|
||||
const autowires: any = {};
|
||||
const properties = Decorator.getClassProperties(target);
|
||||
for (const property in properties) {
|
||||
const autowire = Reflect.getMetadata(AUTOWIRE_KEY, target, property);
|
||||
if (autowire) {
|
||||
autowires[property] = autowire;
|
||||
}
|
||||
}
|
||||
_.merge(define, { autowire: autowires });
|
||||
|
||||
Reflect.defineMetadata(DNS_PROVIDER_CLASS_KEY, define, target);
|
||||
|
||||
target.define = define;
|
||||
dnsProviderRegistry.register(define.name, {
|
||||
define,
|
||||
target,
|
||||
});
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export * from "./api";
|
||||
export * from "./registry";
|
||||
export * from "./decorator";
|
||||
@@ -0,0 +1,4 @@
|
||||
import { Registry } from "@certd/pipeline";
|
||||
|
||||
// @ts-ignore
|
||||
export const dnsProviderRegistry = new Registry();
|
||||
Reference in New Issue
Block a user