refactor: pipeline edit view

This commit is contained in:
xiaojunnuo
2022-10-26 23:29:10 +08:00
parent 370a28c10e
commit e1466737e3
20 changed files with 89 additions and 94 deletions
@@ -1,12 +1,11 @@
import { AbstractRegistrable } from "../registry";
import { PluginDefine } from "./api";
import { Logger } from "log4js";
import { logger } from "../utils/util.log";
import { IAccessService } from "../access/access-service";
import { IContext } from "../core/context";
import { PluginDefine, TaskInput, TaskOutput, TaskPlugin } from "./api";
export abstract class AbstractPlugin extends AbstractRegistrable {
static define: PluginDefine;
export abstract class AbstractPlugin extends AbstractRegistrable<PluginDefine> implements TaskPlugin {
logger: Logger = logger;
// @ts-ignore
accessService: IAccessService;
@@ -25,4 +24,6 @@ export abstract class AbstractPlugin extends AbstractRegistrable {
protected async onInit(): Promise<void> {
//
}
abstract execute(input: TaskInput): Promise<TaskOutput>;
}
+3 -3
View File
@@ -22,7 +22,6 @@ export type Storage = {
export type TaskOutputDefine = {
title: string;
key: string;
value?: any;
storage?: Storage;
};
@@ -38,6 +37,7 @@ export type PluginDefine = Registrable & {
};
export interface TaskPlugin {
getDefine(): PluginDefine;
execute(input: TaskInput): Promise<TaskOutput>;
}
@@ -50,9 +50,9 @@ export type OutputVO = {
export function IsTask(define: (() => PluginDefine) | PluginDefine) {
return function (target: any) {
if (define instanceof Function) {
target.define = define();
target.prototype.define = define();
} else {
target.define = define;
target.prototype.define = define;
}
pluginRegistry.install(target);
@@ -1,12 +1,12 @@
// @ts-ignore
import acme, { Authorization } from "@certd/acme-client";
import * as acme from "@certd/acme-client";
import _ from "lodash";
import { logger } from "../../../utils/util.log";
import { AbstractDnsProvider } from "../../../dns-provider/abstract-dns-provider";
import { IContext } from "../../../core/context";
import { IDnsProvider } from "../../../dns-provider";
import { Challenge } from "@certd/acme-client/types/rfc8555";
console.log("acme", acme);
export class AcmeService {
userContext: IContext;
constructor(options: { userContext: IContext }) {
@@ -155,10 +155,10 @@ export class AcmeService {
email: email,
termsOfServiceAgreed: true,
challengePriority: ["dns-01"],
challengeCreateFn: async (authz: Authorization, challenge: Challenge, keyAuthorization: string): Promise<any> => {
challengeCreateFn: async (authz: acme.Authorization, challenge: Challenge, keyAuthorization: string): Promise<any> => {
return await this.challengeCreateFn(authz, challenge, keyAuthorization, dnsProvider);
},
challengeRemoveFn: async (authz: Authorization, challenge: Challenge, keyAuthorization: string, recordItem: any): Promise<any> => {
challengeRemoveFn: async (authz: acme.Authorization, challenge: Challenge, keyAuthorization: string, recordItem: any): Promise<any> => {
return await this.challengeRemoveFn(authz, challenge, keyAuthorization, recordItem, dnsProvider);
},
});
@@ -17,6 +17,7 @@ export type CertInfo = {
title: "证书申请",
input: {
domains: {
title: "域名",
component: {
name: "a-select",
vModel: "value",
@@ -28,6 +29,7 @@ export type CertInfo = {
helper: "请输入域名",
},
email: {
title: "邮箱",
component: {
name: "a-input",
vModel: "value",
@@ -35,12 +37,14 @@ export type CertInfo = {
helper: "请输入邮箱",
},
dnsProviderType: {
title: "DNS提供商",
component: {
name: "a-select",
},
helper: "请选择dns解析提供商",
},
dnsProviderAccess: {
title: "DNS解析授权",
component: {
name: "access-selector",
},
@@ -49,7 +53,7 @@ export type CertInfo = {
renewDays: {
title: "更新天数",
component: {
name: "a-number",
name: "a-input-number",
value: 20,
},
helper: "到期前多少天后更新证书",
@@ -69,18 +69,17 @@ export class DeployCertToAliyunCDN extends AbstractPlugin implements TaskPlugin
}
async buildParams(input: TaskInput) {
const { certName, domainName, cert } = input;
const { certName, domainName } = input;
const CertName = certName + "-" + dayjs().format("YYYYMMDDHHmmss");
const newCert = (await this.pipelineContext.get(cert)) as CertInfo;
const cert = input.cert as CertInfo;
return {
RegionId: "cn-hangzhou",
DomainName: domainName,
ServerCertificateStatus: "on",
CertName: CertName,
CertType: "upload",
ServerCertificate: newCert.crt,
PrivateKey: newCert.key,
ServerCertificate: cert.crt,
PrivateKey: cert.key,
};
}
@@ -95,7 +94,7 @@ export class DeployCertToAliyunCDN extends AbstractPlugin implements TaskPlugin
checkRet(ret: any) {
if (ret.code != null) {
throw new Error("执行失败:", ret.Message);
throw new Error("执行失败:" + ret.Message);
}
}
}
@@ -7,6 +7,7 @@ import { IsTask, TaskInput, TaskOutput, TaskPlugin } from "../api";
title: "测试插件回声",
input: {
cert: {
title: "cert",
component: {
name: "output-selector",
},
@@ -1,4 +1,5 @@
import { Registry } from "../registry";
import { AbstractPlugin } from "./abstract-plugin";
// @ts-ignore
export const pluginRegistry = new Registry<typeof AbstractPlugin>();