From c6a0fed9e6b3e6abee682ca1ce1b687cfa504b6d Mon Sep 17 00:00:00 2001 From: Thorarinn Sigurdsson Date: Tue, 21 Jan 2020 10:39:36 +0100 Subject: [PATCH] fix(core): allow unknown in task & test results This adds a bit of future-proofing for schema changes to test and task results. If unknown fields are not allowed in task and test results, new fields stored on results generated by newer versions of the framework may cause errors when read by older versions which do not recognize the new fields. --- garden-service/src/types/plugin/base.ts | 63 ++++++++-------- .../src/types/plugin/task/getTaskResult.ts | 73 ++++++++++--------- 2 files changed, 71 insertions(+), 65 deletions(-) diff --git a/garden-service/src/types/plugin/base.ts b/garden-service/src/types/plugin/base.ts index ac7a7adc28a..3b1592bfe67 100644 --- a/garden-service/src/types/plugin/base.ts +++ b/garden-service/src/types/plugin/base.ts @@ -85,36 +85,39 @@ export interface RunResult { output?: string } -export const runResultSchema = joi.object().keys({ - moduleName: joi.string().description("The name of the module that was run."), - command: joi - .array() - .items(joi.string()) - .required() - .description("The command that was run in the module."), - version: joi.string().description("The string version of the module."), - success: joi - .boolean() - .required() - .description("Whether the module was successfully run."), - startedAt: joi - .date() - .required() - .description("When the module run was started."), - completedAt: joi - .date() - .required() - .description("When the module run was completed."), - log: joi - .string() - .allow("") - .default("") - .description("The output log from the run."), - output: joi - .string() - .allow("") - .description("[DEPRECATED - use `log` instead] The output log from the run."), -}) +export const runResultSchema = joi + .object() + .unknown(true) + .keys({ + moduleName: joi.string().description("The name of the module that was run."), + command: joi + .array() + .items(joi.string()) + .required() + .description("The command that was run in the module."), + version: joi.string().description("The string version of the module."), + success: joi + .boolean() + .required() + .description("Whether the module was successfully run."), + startedAt: joi + .date() + .required() + .description("When the module run was started."), + completedAt: joi + .date() + .required() + .description("When the module run was completed."), + log: joi + .string() + .allow("") + .default("") + .description("The output log from the run."), + output: joi + .string() + .allow("") + .description("[DEPRECATED - use `log` instead] The output log from the run."), + }) export const artifactsPathSchema = joi .string() diff --git a/garden-service/src/types/plugin/task/getTaskResult.ts b/garden-service/src/types/plugin/task/getTaskResult.ts index 23adbe2de63..2064be2bb46 100644 --- a/garden-service/src/types/plugin/task/getTaskResult.ts +++ b/garden-service/src/types/plugin/task/getTaskResult.ts @@ -20,41 +20,44 @@ export interface GetTaskResultParams extends PluginTa taskVersion: ModuleVersion } -export const taskResultSchema = joi.object().keys({ - moduleName: joi.string().description("The name of the module that the task belongs to."), - taskName: joi.string().description("The name of the task that was run."), - command: joi - .array() - .items(joi.string()) - .required() - .description("The command that the task ran in the module."), - version: joi.string().description("The string version of the task."), - success: joi - .boolean() - .required() - .description("Whether the task was successfully run."), - startedAt: joi - .date() - .required() - .description("When the task run was started."), - completedAt: joi - .date() - .required() - .description("When the task run was completed."), - log: joi - .string() - .required() - .allow("") - .description("The output log from the run."), - output: joi - .string() - .allow("") - .description("[DEPRECATED - use `log` instead] The output log from the run."), - outputs: joi - .object() - .pattern(/.+/, joiPrimitive()) - .description("A map of primitive values, output from the task."), -}) +export const taskResultSchema = joi + .object() + .unknown(true) + .keys({ + moduleName: joi.string().description("The name of the module that the task belongs to."), + taskName: joi.string().description("The name of the task that was run."), + command: joi + .array() + .items(joi.string()) + .required() + .description("The command that the task ran in the module."), + version: joi.string().description("The string version of the task."), + success: joi + .boolean() + .required() + .description("Whether the task was successfully run."), + startedAt: joi + .date() + .required() + .description("When the task run was started."), + completedAt: joi + .date() + .required() + .description("When the task run was completed."), + log: joi + .string() + .required() + .allow("") + .description("The output log from the run."), + output: joi + .string() + .allow("") + .description("[DEPRECATED - use `log` instead] The output log from the run."), + outputs: joi + .object() + .pattern(/.+/, joiPrimitive()) + .description("A map of primitive values, output from the task."), + }) export const getTaskResult = { description: dedent`