mirror of https://github.com/certd/certd
refactor: register
parent
e123ec4089
commit
9747d40734
|
@ -160,7 +160,7 @@ export class Executor {
|
||||||
});
|
});
|
||||||
|
|
||||||
Decorator.inject(define.autowire, instance, context);
|
Decorator.inject(define.autowire, instance, context);
|
||||||
await instance.onInit();
|
await instance.onInstance();
|
||||||
await instance.execute();
|
await instance.execute();
|
||||||
|
|
||||||
//输出到output context
|
//输出到output context
|
||||||
|
|
|
@ -34,7 +34,7 @@ export type PluginDefine = Registrable & {
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface ITaskPlugin {
|
export interface ITaskPlugin {
|
||||||
onInit(): Promise<void>;
|
onInstance(): Promise<void>;
|
||||||
execute(): Promise<void>;
|
execute(): Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,10 @@ export class EchoPlugin implements ITaskPlugin {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
logger: ILogger;
|
logger: ILogger;
|
||||||
|
|
||||||
|
onInstance(): Promise<void> {
|
||||||
|
throw new Error("Method not implemented.");
|
||||||
|
}
|
||||||
|
|
||||||
async execute(): Promise<void> {
|
async execute(): Promise<void> {
|
||||||
return Promise.resolve(undefined);
|
return Promise.resolve(undefined);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ export class EchoPlugin implements ITaskPlugin {
|
||||||
certInfo!: any;
|
certInfo!: any;
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||||
async onInit(): Promise<void> {}
|
async onInstance(): Promise<void> {}
|
||||||
async execute(): Promise<void> {
|
async execute(): Promise<void> {
|
||||||
console.log("input :cert", this.cert);
|
console.log("input :cert", this.cert);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ export class AliyunDnsProvider implements IDnsProvider {
|
||||||
access!: AliyunAccess;
|
access!: AliyunAccess;
|
||||||
@Autowire()
|
@Autowire()
|
||||||
logger!: ILogger;
|
logger!: ILogger;
|
||||||
async onInit() {
|
async onInstance() {
|
||||||
const access: any = this.access;
|
const access: any = this.access;
|
||||||
this.client = new Core({
|
this.client = new Core({
|
||||||
accessKeyId: access.accessKeyId,
|
accessKeyId: access.accessKeyId,
|
||||||
|
|
|
@ -109,7 +109,7 @@ export class DeployCertToAliyunAckIngressPlugin implements ITaskPlugin {
|
||||||
logger!: ILogger;
|
logger!: ILogger;
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||||
async onInit(): Promise<void> {}
|
async onInstance(): Promise<void> {}
|
||||||
async execute(): Promise<void> {
|
async execute(): Promise<void> {
|
||||||
console.log("开始部署证书到阿里云cdn");
|
console.log("开始部署证书到阿里云cdn");
|
||||||
const { regionId, ingressClass, clusterId, isPrivateIpAddress, cert } = this;
|
const { regionId, ingressClass, clusterId, isPrivateIpAddress, cert } = this;
|
||||||
|
|
|
@ -56,7 +56,7 @@ export class DeployCertToAliyunCDN implements ITaskPlugin {
|
||||||
@Autowire()
|
@Autowire()
|
||||||
logger!: ILogger;
|
logger!: ILogger;
|
||||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||||
async onInit() {}
|
async onInstance() {}
|
||||||
async execute(): Promise<void> {
|
async execute(): Promise<void> {
|
||||||
console.log("开始部署证书到阿里云cdn");
|
console.log("开始部署证书到阿里云cdn");
|
||||||
const access = (await this.accessService.getById(this.accessId)) as AliyunAccess;
|
const access = (await this.accessService.getById(this.accessId)) as AliyunAccess;
|
||||||
|
|
|
@ -66,7 +66,7 @@ export class UploadCertToAliyun implements ITaskPlugin {
|
||||||
logger!: Logger;
|
logger!: Logger;
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||||
async onInit() {}
|
async onInstance() {}
|
||||||
|
|
||||||
async execute(): Promise<void> {
|
async execute(): Promise<void> {
|
||||||
console.log("开始部署证书到阿里云cdn");
|
console.log("开始部署证书到阿里云cdn");
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
import { IAccessService } from "@certd/pipeline";
|
||||||
|
import { hauweiSecret } from "../user.secret";
|
||||||
|
import { HuaweiAccess } from "@certd/plugin-huawei";
|
||||||
|
export class AccessServiceTest implements IAccessService {
|
||||||
|
async getById(id: any): Promise<any> {
|
||||||
|
return {
|
||||||
|
...hauweiSecret,
|
||||||
|
} as HuaweiAccess;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,66 @@
|
||||||
|
import { ConcurrencyStrategy, NextStrategy, Pipeline, RunStrategy } from "@certd/pipeline";
|
||||||
|
|
||||||
|
let idIndex = 0;
|
||||||
|
function generateId() {
|
||||||
|
idIndex++;
|
||||||
|
return idIndex + "";
|
||||||
|
}
|
||||||
|
export const pipeline: Pipeline = {
|
||||||
|
version: 1,
|
||||||
|
id: generateId(),
|
||||||
|
title: "华为管道测试",
|
||||||
|
userId: 1,
|
||||||
|
triggers: [],
|
||||||
|
stages: [
|
||||||
|
{
|
||||||
|
id: generateId(),
|
||||||
|
title: "证书申请阶段",
|
||||||
|
concurrency: ConcurrencyStrategy.Serial,
|
||||||
|
next: NextStrategy.AllSuccess,
|
||||||
|
tasks: [
|
||||||
|
{
|
||||||
|
id: generateId(),
|
||||||
|
title: "申请证书任务",
|
||||||
|
steps: [
|
||||||
|
{
|
||||||
|
id: generateId(),
|
||||||
|
title: "申请证书",
|
||||||
|
type: "CertApply",
|
||||||
|
input: {
|
||||||
|
domains: ["*.powerleader.chat"],
|
||||||
|
email: "xiaojunnuo@qq.com",
|
||||||
|
dnsProviderType: "huawei",
|
||||||
|
accessId: "111",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: generateId(),
|
||||||
|
title: "证书部署阶段",
|
||||||
|
concurrency: ConcurrencyStrategy.Serial,
|
||||||
|
next: NextStrategy.AllSuccess,
|
||||||
|
tasks: [
|
||||||
|
{
|
||||||
|
id: generateId(),
|
||||||
|
title: "测试输出参数任务",
|
||||||
|
steps: [
|
||||||
|
{
|
||||||
|
id: generateId(),
|
||||||
|
title: "输出参数(echo插件)",
|
||||||
|
type: "EchoPlugin",
|
||||||
|
input: {
|
||||||
|
cert: "cert",
|
||||||
|
},
|
||||||
|
strategy: {
|
||||||
|
runStrategy: RunStrategy.SkipWhenSucceed,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
|
@ -0,0 +1,19 @@
|
||||||
|
//import { expect } from "chai";
|
||||||
|
import "mocha";
|
||||||
|
import { Executor, RunHistory, FileStorage } from "@certd/pipeline";
|
||||||
|
import { pipeline } from "./pipeline.huawei";
|
||||||
|
import { AccessServiceTest } from "./access-service-test";
|
||||||
|
import "../../src";
|
||||||
|
import "../plugin/echo-plugin";
|
||||||
|
describe("pipeline-hauwei-test", function () {
|
||||||
|
it("#pipeline", async function () {
|
||||||
|
this.timeout(120000);
|
||||||
|
function onChanged(history: RunHistory) {
|
||||||
|
console.log("changed:");
|
||||||
|
}
|
||||||
|
|
||||||
|
const executor = new Executor({ userId: "test", pipeline, onChanged, accessService: new AccessServiceTest(), storage: new FileStorage() });
|
||||||
|
await executor.run(1, "user");
|
||||||
|
// expect(define.name).eq("EchoPlugin");
|
||||||
|
});
|
||||||
|
});
|
|
@ -4,6 +4,7 @@ import { Executor, RunHistory, FileStorage } from "@certd/pipeline";
|
||||||
import { pipeline } from "./pipeline.define";
|
import { pipeline } from "./pipeline.define";
|
||||||
import { AccessServiceTest } from "./access-service-test";
|
import { AccessServiceTest } from "./access-service-test";
|
||||||
import "../../src";
|
import "../../src";
|
||||||
|
import "../plugin/echo-plugin";
|
||||||
describe("pipeline", function () {
|
describe("pipeline", function () {
|
||||||
it("#pipeline", async function () {
|
it("#pipeline", async function () {
|
||||||
this.timeout(120000);
|
this.timeout(120000);
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
import { Autowire, IsTaskPlugin, TaskInput, ITaskPlugin } from "@certd/pipeline";
|
||||||
|
|
||||||
|
@IsTaskPlugin({
|
||||||
|
name: "EchoPlugin",
|
||||||
|
title: "测试插件",
|
||||||
|
desc: "test",
|
||||||
|
})
|
||||||
|
export class EchoPlugin implements ITaskPlugin {
|
||||||
|
@TaskInput({
|
||||||
|
title: "测试属性",
|
||||||
|
component: {
|
||||||
|
name: "text",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
test?: string;
|
||||||
|
|
||||||
|
async execute(): Promise<void> {
|
||||||
|
console.log("output", this.test);
|
||||||
|
}
|
||||||
|
|
||||||
|
onInstance(): Promise<void> {
|
||||||
|
return Promise.resolve(undefined);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
new EchoPlugin();
|
|
@ -17,7 +17,7 @@ export type RemoveRecordOptions = CreateRecordOptions & {
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface IDnsProvider {
|
export interface IDnsProvider {
|
||||||
onInit(): Promise<void>;
|
onInstance(): Promise<void>;
|
||||||
createRecord(options: CreateRecordOptions): Promise<any>;
|
createRecord(options: CreateRecordOptions): Promise<any>;
|
||||||
removeRecord(options: RemoveRecordOptions): Promise<any>;
|
removeRecord(options: RemoveRecordOptions): Promise<any>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -156,7 +156,7 @@ export class CertApplyPlugin implements ITaskPlugin {
|
||||||
})
|
})
|
||||||
cert?: CertInfo;
|
cert?: CertInfo;
|
||||||
|
|
||||||
async onInit() {
|
async onInstance() {
|
||||||
this.acme = new AcmeService({ userContext: this.userContext, logger: this.logger });
|
this.acme = new AcmeService({ userContext: this.userContext, logger: this.logger });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,7 +228,7 @@ export class CertApplyPlugin implements ITaskPlugin {
|
||||||
const dnsProvider: IDnsProvider = new DnsProviderClass();
|
const dnsProvider: IDnsProvider = new DnsProviderClass();
|
||||||
const context = { access, logger: this.logger, http: this.http };
|
const context = { access, logger: this.logger, http: this.http };
|
||||||
Decorator.inject(dnsProviderDefine.autowire, dnsProvider, context);
|
Decorator.inject(dnsProviderDefine.autowire, dnsProvider, context);
|
||||||
await dnsProvider.onInit();
|
await dnsProvider.onInstance();
|
||||||
|
|
||||||
const cert = await this.acme.order({
|
const cert = await this.acme.order({
|
||||||
email,
|
email,
|
||||||
|
|
|
@ -48,7 +48,7 @@ export class HostShellExecutePlugin implements ITaskPlugin {
|
||||||
logger!: ILogger;
|
logger!: ILogger;
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||||
async onInit() {}
|
async onInstance() {}
|
||||||
async execute(): Promise<void> {
|
async execute(): Promise<void> {
|
||||||
const { script, accessId } = this;
|
const { script, accessId } = this;
|
||||||
const connectConf = this.accessService.getById(accessId);
|
const connectConf = this.accessService.getById(accessId);
|
||||||
|
|
|
@ -64,7 +64,7 @@ export class UploadCertToHostPlugin implements ITaskPlugin {
|
||||||
})
|
})
|
||||||
hostKeyPath!: string;
|
hostKeyPath!: string;
|
||||||
|
|
||||||
async onInit() {}
|
async onInstance() {}
|
||||||
async execute(): Promise<void> {
|
async execute(): Promise<void> {
|
||||||
const { crtPath, keyPath, cert, accessId, sudo } = this;
|
const { crtPath, keyPath, cert, accessId, sudo } = this;
|
||||||
const connectConf = this.accessService.getById(accessId);
|
const connectConf = this.accessService.getById(accessId);
|
||||||
|
|
|
@ -17,7 +17,7 @@ export class HuaweiDnsProvider implements IDnsProvider {
|
||||||
@Autowire()
|
@Autowire()
|
||||||
logger!: ILogger;
|
logger!: ILogger;
|
||||||
endpoint = "https://domains-external.myhuaweicloud.com";
|
endpoint = "https://domains-external.myhuaweicloud.com";
|
||||||
async onInit() {
|
async onInstance() {
|
||||||
const access: any = this.access;
|
const access: any = this.access;
|
||||||
this.client = new HuaweiYunClient(access);
|
this.client = new HuaweiYunClient(access);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ export class DnspodDnsProvider implements IDnsProvider {
|
||||||
|
|
||||||
loginToken: any;
|
loginToken: any;
|
||||||
|
|
||||||
async onInit() {
|
async onInstance() {
|
||||||
const access: DnspodAccess = this.access as DnspodAccess;
|
const access: DnspodAccess = this.access as DnspodAccess;
|
||||||
this.loginToken = access.id + "," + access.token;
|
this.loginToken = access.id + "," + access.token;
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ export class DeployToCdnPlugin implements ITaskPlugin {
|
||||||
logger!: ILogger;
|
logger!: ILogger;
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||||
async onInit() {}
|
async onInstance() {}
|
||||||
|
|
||||||
async execute(): Promise<void> {
|
async execute(): Promise<void> {
|
||||||
const accessProvider: TencentAccess = (await this.accessService.getById(this.accessId)) as TencentAccess;
|
const accessProvider: TencentAccess = (await this.accessService.getById(this.accessId)) as TencentAccess;
|
||||||
|
|
|
@ -78,7 +78,7 @@ export class DeployToClbPlugin implements ITaskPlugin {
|
||||||
logger!: ILogger;
|
logger!: ILogger;
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||||
async onInit() {}
|
async onInstance() {}
|
||||||
async execute(): Promise<void> {
|
async execute(): Promise<void> {
|
||||||
const accessProvider = (await this.accessService.getById(this.accessId)) as TencentAccess;
|
const accessProvider = (await this.accessService.getById(this.accessId)) as TencentAccess;
|
||||||
const client = this.getClient(accessProvider, this.region);
|
const client = this.getClient(accessProvider, this.region);
|
||||||
|
|
|
@ -87,7 +87,7 @@ export class DeployCertToTencentTKEIngressPlugin implements ITaskPlugin {
|
||||||
accessService!: IAccessService;
|
accessService!: IAccessService;
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||||
async onInit() {}
|
async onInstance() {}
|
||||||
|
|
||||||
async execute(): Promise<void> {
|
async execute(): Promise<void> {
|
||||||
const accessProvider = this.accessService.getById(this.accessId);
|
const accessProvider = this.accessService.getById(this.accessId);
|
||||||
|
|
|
@ -49,7 +49,7 @@ export class UploadToTencentPlugin implements ITaskPlugin {
|
||||||
logger!: ILogger;
|
logger!: ILogger;
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||||
async onInit() {}
|
async onInstance() {}
|
||||||
|
|
||||||
async execute(): Promise<void> {
|
async execute(): Promise<void> {
|
||||||
const { accessId, name, cert } = this;
|
const { accessId, name, cert } = this;
|
||||||
|
|
|
@ -19,7 +19,7 @@ export class EchoPlugin implements ITaskPlugin {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
logger: ILogger;
|
logger: ILogger;
|
||||||
|
|
||||||
async onInit(){}
|
async onInstance(){}
|
||||||
|
|
||||||
async execute(): Promise<void> {
|
async execute(): Promise<void> {
|
||||||
return Promise.resolve(undefined);
|
return Promise.resolve(undefined);
|
||||||
|
|
Loading…
Reference in New Issue