From f776dc3e537e3d11a802c4be840ad96aa3eb814f Mon Sep 17 00:00:00 2001 From: Joseph Garrone Date: Mon, 2 Dec 2024 16:42:19 +0100 Subject: [PATCH] Refactor --- .../decoupledLogic/computeHelmValues.ts | 72 ++++++++----------- 1 file changed, 29 insertions(+), 43 deletions(-) diff --git a/web/src/core/usecases/launcher/decoupledLogic/computeHelmValues.ts b/web/src/core/usecases/launcher/decoupledLogic/computeHelmValues.ts index ef01c5ee8..31e9a4384 100644 --- a/web/src/core/usecases/launcher/decoupledLogic/computeHelmValues.ts +++ b/web/src/core/usecases/launcher/decoupledLogic/computeHelmValues.ts @@ -126,6 +126,35 @@ export function computeHelmValues_rec(params: { return constValue; } + const helmValuesSchemaType = getJSONSchemaType(helmValuesSchema); + + schema_is_object_with_known_properties: { + if (helmValuesSchemaType !== "object") { + break schema_is_object_with_known_properties; + } + + const { properties } = helmValuesSchema; + + if (properties === undefined) { + break schema_is_object_with_known_properties; + } + + return Object.fromEntries( + Object.entries(properties).map(([propertyName, propertySchema]) => [ + propertyName, + computeHelmValues_rec({ + helmValuesSchema: propertySchema, + helmValuesYaml_parsed: + helmValuesYaml_parsed instanceof Object && + !(helmValuesYaml_parsed instanceof Array) + ? helmValuesYaml_parsed[propertyName] + : undefined, + xOnyxiaContext + }) + ]) + ); + } + use_x_onyxia_overwriteDefaultWith: { const { overwriteDefaultWith } = helmValuesSchema["x-onyxia"] ?? {}; @@ -133,13 +162,6 @@ export function computeHelmValues_rec(params: { break use_x_onyxia_overwriteDefaultWith; } - if ( - helmValuesSchema.type === "object" && - helmValuesSchema.properties !== undefined - ) { - break use_x_onyxia_overwriteDefaultWith; - } - const resolvedValue = resolveXOnyxiaValueReference({ expression: overwriteDefaultWith, xOnyxiaContext @@ -172,13 +194,6 @@ export function computeHelmValues_rec(params: { break use_default; } - if ( - helmValuesSchema.type === "object" && - helmValuesSchema.properties !== undefined - ) { - break use_default; - } - const { isValid } = validateValueAgainstJSONSchema({ helmValuesSchema, xOnyxiaContext, @@ -192,35 +207,6 @@ export function computeHelmValues_rec(params: { return defaultValue; } - const helmValuesSchemaType = getJSONSchemaType(helmValuesSchema); - - schema_is_object_with_known_properties: { - if (helmValuesSchemaType !== "object") { - break schema_is_object_with_known_properties; - } - - const { properties } = helmValuesSchema; - - if (properties === undefined) { - break schema_is_object_with_known_properties; - } - - return Object.fromEntries( - Object.entries(properties).map(([propertyName, propertySchema]) => [ - propertyName, - computeHelmValues_rec({ - helmValuesSchema: propertySchema, - helmValuesYaml_parsed: - helmValuesYaml_parsed instanceof Object && - !(helmValuesYaml_parsed instanceof Array) - ? helmValuesYaml_parsed[propertyName] - : undefined, - xOnyxiaContext - }) - ]) - ); - } - use_values_yaml: { if (helmValuesYaml_parsed === undefined) { break use_values_yaml;