From e950322232e19d1263b8552eefa5b0150fd7864e Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Mon, 10 Jul 2023 11:52:38 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E8=AF=81=E4=B9=A6=E5=88=B0=E8=85=BE=E8=AE=AF=E4=BA=91=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/pipeline/src/d.ts/pipeline.ts | 2 +- .../test/pipeline/access-service-test.ts | 10 ++++++++- .../test/pipeline/pipeline.define.ts | 11 ++++++++++ .../plugin-all/test/pipeline/pipeline.test.ts | 11 ++++++++-- .../src/access/dnspod-access.ts | 22 ++++++++++++++++--- .../src/dns-provider/dnspod-dns-provider.ts | 8 ++++--- .../src/plugin/deploy-to-cdn/index.ts | 11 ++++++++++ .../src/plugin/deploy-to-tke-ingress/index.ts | 2 +- .../src/plugin/upload-to-tencent/index.ts | 4 ++-- 9 files changed, 68 insertions(+), 13 deletions(-) diff --git a/packages/core/pipeline/src/d.ts/pipeline.ts b/packages/core/pipeline/src/d.ts/pipeline.ts index 148c12ce..3def3483 100644 --- a/packages/core/pipeline/src/d.ts/pipeline.ts +++ b/packages/core/pipeline/src/d.ts/pipeline.ts @@ -88,7 +88,7 @@ export type Pipeline = Runnable & { userId: any; stages: Stage[]; triggers: Trigger[]; - notifications: Notification[]; + notifications?: Notification[]; }; export type Context = { diff --git a/packages/plugins/plugin-all/test/pipeline/access-service-test.ts b/packages/plugins/plugin-all/test/pipeline/access-service-test.ts index c66c7fe7..f17cec28 100644 --- a/packages/plugins/plugin-all/test/pipeline/access-service-test.ts +++ b/packages/plugins/plugin-all/test/pipeline/access-service-test.ts @@ -1,6 +1,7 @@ -import { IAccessService } from "@certd/pipeline"; +import { EmailSend, IAccessService, IEmailService } from "@certd/pipeline"; import { AliyunAccess } from "@certd/plugin-aliyun"; import { aliyunSecret } from "../user.secret"; + export class AccessServiceTest implements IAccessService { async getById(id: any): Promise { return { @@ -8,3 +9,10 @@ export class AccessServiceTest implements IAccessService { } as AliyunAccess; } } + +export class EmailServiceTest implements IEmailService { + send(email: EmailSend): Promise { + console.log("send email", email); + return Promise.resolve(undefined); + } +} diff --git a/packages/plugins/plugin-all/test/pipeline/pipeline.define.ts b/packages/plugins/plugin-all/test/pipeline/pipeline.define.ts index 194865c8..de74350c 100644 --- a/packages/plugins/plugin-all/test/pipeline/pipeline.define.ts +++ b/packages/plugins/plugin-all/test/pipeline/pipeline.define.ts @@ -58,6 +58,17 @@ export const pipeline: Pipeline = { runStrategy: RunStrategy.SkipWhenSucceed, }, }, + { + id: generateId(), + title: "上传证书到腾讯云", + type: "EchoPlugin", + input: { + cert: "cert", + }, + strategy: { + runStrategy: RunStrategy.SkipWhenSucceed, + }, + }, ], }, ], diff --git a/packages/plugins/plugin-all/test/pipeline/pipeline.test.ts b/packages/plugins/plugin-all/test/pipeline/pipeline.test.ts index 408044e2..2723873e 100644 --- a/packages/plugins/plugin-all/test/pipeline/pipeline.test.ts +++ b/packages/plugins/plugin-all/test/pipeline/pipeline.test.ts @@ -1,7 +1,7 @@ import "mocha"; import { Executor, FileStorage, RunHistory } from "@certd/pipeline"; import { pipeline } from "./pipeline.define"; -import { AccessServiceTest } from "./access-service-test"; +import { AccessServiceTest, EmailServiceTest } from "./access-service-test"; import "../../src"; import "../plugin/echo-plugin"; @@ -13,7 +13,14 @@ describe("pipeline", function () { console.log("changed:"); } - const executor = new Executor({ userId: "test", pipeline, onChanged, accessService: new AccessServiceTest(), storage: new FileStorage() }); + const executor = new Executor({ + userId: "test", + pipeline, + onChanged, + accessService: new AccessServiceTest(), + emailService: new EmailServiceTest(), + storage: new FileStorage(), + }); await executor.run(1, "user"); // expect(define.name).eq("EchoPlugin"); }); diff --git a/packages/plugins/plugin-tencent/src/access/dnspod-access.ts b/packages/plugins/plugin-tencent/src/access/dnspod-access.ts index 6e5ab282..20482a9c 100644 --- a/packages/plugins/plugin-tencent/src/access/dnspod-access.ts +++ b/packages/plugins/plugin-tencent/src/access/dnspod-access.ts @@ -7,13 +7,20 @@ import { IsAccess, AccessInput } from "@certd/pipeline"; }) export class DnspodAccess { @AccessInput({ - title: "token", + title: "端点", component: { - placeholder: "开放接口token", + placeholder: "endpoint", + name: "a-select", + vModel: "value", + options: [ + { value: "https://dnsapi.cn", label: "中国站" }, + { value: "https://api.dnspod.com", label: "国际站" }, + ], }, rules: [{ required: true, message: "该项必填" }], }) - token = ""; + endpoint = ""; + @AccessInput({ title: "账户id", component: { @@ -22,6 +29,15 @@ export class DnspodAccess { rules: [{ required: true, message: "该项必填" }], }) id = ""; + + @AccessInput({ + title: "token", + component: { + placeholder: "开放接口token", + }, + rules: [{ required: true, message: "该项必填" }], + }) + token = ""; } new DnspodAccess(); diff --git a/packages/plugins/plugin-tencent/src/dns-provider/dnspod-dns-provider.ts b/packages/plugins/plugin-tencent/src/dns-provider/dnspod-dns-provider.ts index 2d2e25cd..0f55bf86 100644 --- a/packages/plugins/plugin-tencent/src/dns-provider/dnspod-dns-provider.ts +++ b/packages/plugins/plugin-tencent/src/dns-provider/dnspod-dns-provider.ts @@ -20,9 +20,11 @@ export class DnspodDnsProvider implements IDnsProvider { loginToken: any; + endpoint = ""; async onInstance() { const access: DnspodAccess = this.access as DnspodAccess; this.loginToken = access.id + "," + access.token; + this.endpoint = access.endpoint || "https://dnsapi.cn"; } async doRequest(options: any, successCodes: string[] = []) { @@ -51,7 +53,7 @@ export class DnspodDnsProvider implements IDnsProvider { async getDomainList() { const ret = await this.doRequest({ - url: "https://dnsapi.cn/Domain.List", + url: this.access.endpoint + "/Domain.List", }); this.logger.debug("dnspod 域名列表:", ret.domains); return ret.domains; @@ -66,7 +68,7 @@ export class DnspodDnsProvider implements IDnsProvider { const ret = await this.doRequest( { - url: "https://dnsapi.cn/Record.Create", + url: this.access.endpoint + "/Record.Create", formData: { domain, sub_domain: rr, @@ -87,7 +89,7 @@ export class DnspodDnsProvider implements IDnsProvider { const domain = await this.matchDomain(fullRecord); const ret = await this.doRequest({ - url: "https://dnsapi.cn/Record.Remove", + url: this.access.endpoint + "/Record.Remove", formData: { domain, record_id: record.id, diff --git a/packages/plugins/plugin-tencent/src/plugin/deploy-to-cdn/index.ts b/packages/plugins/plugin-tencent/src/plugin/deploy-to-cdn/index.ts index 357922cf..b74dbc3d 100644 --- a/packages/plugins/plugin-tencent/src/plugin/deploy-to-cdn/index.ts +++ b/packages/plugins/plugin-tencent/src/plugin/deploy-to-cdn/index.ts @@ -47,6 +47,17 @@ export class DeployToCdnPlugin extends AbstractTaskPlugin { }) domainName!: string; + @TaskInput({ + title: "CDN接口", + helper: "CDN接口端点", + component: { + name: "a-select", + type: "tencent", + }, + required: true, + }) + endpoint!: string; + accessService!: IAccessService; logger!: ILogger; diff --git a/packages/plugins/plugin-tencent/src/plugin/deploy-to-tke-ingress/index.ts b/packages/plugins/plugin-tencent/src/plugin/deploy-to-tke-ingress/index.ts index 21d36a6c..9a5abf26 100644 --- a/packages/plugins/plugin-tencent/src/plugin/deploy-to-tke-ingress/index.ts +++ b/packages/plugins/plugin-tencent/src/plugin/deploy-to-tke-ingress/index.ts @@ -87,7 +87,7 @@ export class DeployCertToTencentTKEIngressPlugin extends AbstractTaskPlugin { this.logger = this.ctx.logger; } async execute(): Promise { - const accessProvider = this.accessService.getById(this.accessId); + const accessProvider = await this.accessService.getById(this.accessId); const tkeClient = this.getTkeClient(accessProvider, this.region); const kubeConfigStr = await this.getTkeKubeConfig(tkeClient, this.clusterId); diff --git a/packages/plugins/plugin-tencent/src/plugin/upload-to-tencent/index.ts b/packages/plugins/plugin-tencent/src/plugin/upload-to-tencent/index.ts index 8e9ad086..1f7bede1 100644 --- a/packages/plugins/plugin-tencent/src/plugin/upload-to-tencent/index.ts +++ b/packages/plugins/plugin-tencent/src/plugin/upload-to-tencent/index.ts @@ -52,7 +52,7 @@ export class UploadToTencentPlugin extends AbstractTaskPlugin { async execute(): Promise { const { accessId, name, cert } = this; - const accessProvider = this.accessService.getById(accessId); + const accessProvider = await this.accessService.getById(accessId); const certName = this.appendTimeSuffix(name || cert.domain); const client = this.getClient(accessProvider); @@ -96,7 +96,7 @@ export class UploadToTencentPlugin extends AbstractTaskPlugin { // async rollback({ input }) { // const { accessId } = input; - // const accessProvider = this.accessService.getById(accessId); + // const accessProvider = await this.accessService.getById(accessId); // const client = this.getClient(accessProvider); // // const { tencentCertId } = context;