diff --git a/packages/core/pipeline/src/core/context.ts b/packages/core/pipeline/src/core/context.ts index c0248866..61f8289f 100644 --- a/packages/core/pipeline/src/core/context.ts +++ b/packages/core/pipeline/src/core/context.ts @@ -1,8 +1,10 @@ import { IStorage, MemoryStorage } from "./storage"; export interface IContext { - get(key: string): Promise; - set(key: string, value: any): Promise; + get(key: string): Promise; + set(key: string, value: string): Promise; + getObj(key: string): Promise; + setObj(key: string, value: any): Promise; } export class ContextFactory { @@ -32,8 +34,15 @@ export class StorageContext implements IContext { this.scope = scope; this.namespace = namespace; } - async get(key: string): Promise { - const str = await this.storage.get(this.scope, this.namespace, key); + + async get(key: string) { + return await this.storage.get(this.scope, this.namespace, key); + } + async set(key: string, value: string) { + return await this.storage.set(this.scope, this.namespace, key, value); + } + async getObj(key: string): Promise { + const str = await this.get(key); if (str) { const store = JSON.parse(str); return store.value; @@ -41,7 +50,7 @@ export class StorageContext implements IContext { return null; } - async set(key: string, value: any) { - await this.storage.set(this.scope, this.namespace, key, JSON.stringify({ value })); + async setObj(key: string, value: any) { + await this.set(key, JSON.stringify({ value })); } } diff --git a/packages/core/pipeline/src/core/executor.ts b/packages/core/pipeline/src/core/executor.ts index 436e8163..95f41b06 100644 --- a/packages/core/pipeline/src/core/executor.ts +++ b/packages/core/pipeline/src/core/executor.ts @@ -53,8 +53,8 @@ export class Executor { if (runnable.strategy?.runStrategy === RunStrategy.SkipWhenSucceed) { //如果是成功后跳过策略 - const lastResult = await this.pipelineContext.get(contextKey); - const lastInput = await this.pipelineContext.get(inputKey); + const lastResult = await this.pipelineContext.getObj(contextKey); + const lastInput = await this.pipelineContext.getObj(inputKey); let inputChanged = false; //TODO 参数不变 if (runnableType === "step") { @@ -73,12 +73,12 @@ export class Executor { try { await run(); this.runtime.success(runnable); - await this.pipelineContext.set(contextKey, ResultType.success); + await this.pipelineContext.setObj(contextKey, ResultType.success); await this.onChanged(this.runtime); return ResultType.success; } catch (e: any) { this.runtime.error(runnable, e); - await this.pipelineContext.set(contextKey, ResultType.error); + await this.pipelineContext.setObj(contextKey, ResultType.error); await this.onChanged(this.runtime); throw e; } finally { diff --git a/packages/plugins/plugin-all/test/huawei/pipeline.huawei.ts b/packages/plugins/plugin-all/test/huawei/pipeline.huawei.ts index 35476fc7..b2bc9c29 100644 --- a/packages/plugins/plugin-all/test/huawei/pipeline.huawei.ts +++ b/packages/plugins/plugin-all/test/huawei/pipeline.huawei.ts @@ -7,7 +7,7 @@ function generateId() { } export const pipeline: Pipeline = { version: 1, - id: "3", + id: "huawei.test", title: "华为管道测试", userId: 1, triggers: [], diff --git a/packages/plugins/plugin-all/test/pipeline/pipeline.define.ts b/packages/plugins/plugin-all/test/pipeline/pipeline.define.ts index a4f327c5..194865c8 100644 --- a/packages/plugins/plugin-all/test/pipeline/pipeline.define.ts +++ b/packages/plugins/plugin-all/test/pipeline/pipeline.define.ts @@ -7,7 +7,7 @@ function generateId() { } export const pipeline: Pipeline = { version: 1, - id: generateId(), + id: "aliyun.test", title: "测试管道", userId: 1, triggers: [], diff --git a/packages/plugins/plugin-cert/src/plugin/cert-plugin/acme.ts b/packages/plugins/plugin-cert/src/plugin/cert-plugin/acme.ts index 42b6a3fb..ed745aa5 100644 --- a/packages/plugins/plugin-cert/src/plugin/cert-plugin/acme.ts +++ b/packages/plugins/plugin-cert/src/plugin/cert-plugin/acme.ts @@ -17,8 +17,8 @@ export class AcmeService { }); } - async getAccountConfig(email: string) { - return (await this.userContext.get(this.buildAccountKey(email))) || {}; + async getAccountConfig(email: string): Promise { + return (await this.userContext.getObj(this.buildAccountKey(email))) || {}; } buildAccountKey(email: string) { @@ -26,7 +26,7 @@ export class AcmeService { } async saveAccountConfig(email: string, conf: any) { - await this.userContext.set(this.buildAccountKey(email), conf); + await this.userContext.setObj(this.buildAccountKey(email), conf); } async getAcmeClient(email: string, isTest = false): Promise { diff --git a/packages/plugins/plugin-cert/src/plugin/cert-plugin/index.ts b/packages/plugins/plugin-cert/src/plugin/cert-plugin/index.ts index d587faf6..39c7a336 100644 --- a/packages/plugins/plugin-cert/src/plugin/cert-plugin/index.ts +++ b/packages/plugins/plugin-cert/src/plugin/cert-plugin/index.ts @@ -183,9 +183,9 @@ export class CertApplyPlugin implements ITaskPlugin { } let inputChanged = false; - const inputCacheKey = "input.cert"; - const oldInputStr = await this.pipelineContext.get(inputCacheKey); - await this.pipelineContext.set(inputCacheKey, this.cert); + const inputCacheKey = "input.domains"; + const oldInputStr = await this.pipelineContext.getObj(inputCacheKey); + await this.pipelineContext.setObj(inputCacheKey, this.domains); const oldInput = JSON.stringify(oldInputStr); const thisInput = JSON.stringify(this.cert); if (oldInput !== thisInput) { @@ -276,14 +276,14 @@ export class CertApplyPlugin implements ITaskPlugin { key: this.formatCert(cert.key), csr: this.formatCert(cert.csr), }; - await this.pipelineContext.set("cert", newCert); + await this.pipelineContext.setObj("cert", newCert); await this.pipelineContext.set("cert.crt", newCert.crt); await this.pipelineContext.set("cert.key", newCert.key); await this.pipelineContext.set("cert.csr", newCert.csr); } async readCurrentCert() { - const cert: any = await this.pipelineContext.get("cert"); + const cert: any = await this.pipelineContext.getObj("cert"); if (cert == null) { return undefined; }