From 0a3aba6f66a02b1dbf36553e92cd0a46754e984d Mon Sep 17 00:00:00 2001 From: otomi-admin <63190600+ferruhcihan@users.noreply.github.com> Date: Tue, 23 Sep 2025 09:20:00 +0200 Subject: [PATCH] feat: add deepQuote for yaml stringify --- src/otomi-stack.ts | 9 ++++++--- src/utils/yamlUtils.ts | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 src/utils/yamlUtils.ts diff --git a/src/otomi-stack.ts b/src/otomi-stack.ts index c5e90c31..d2ff8502 100644 --- a/src/otomi-stack.ts +++ b/src/otomi-stack.ts @@ -67,6 +67,7 @@ import { getValuesSchema, removeBlankAttributes, } from 'src/utils' +import { deepQuote } from 'src/utils/yamlUtils' import { cleanEnv, CUSTOM_ROOT_CA, @@ -1830,9 +1831,11 @@ export default class OtomiStack { } async editWorkloadValues(teamId: string, name: string, data: WorkloadValues): Promise { - const workload = this.repoService - .getTeamConfigService(teamId) - .patchWorkload(name, { spec: { values: stringifyYaml(data.values) } }) + const workload = this.repoService.getTeamConfigService(teamId).patchWorkload(name, { + spec: { + values: stringifyYaml(deepQuote(data.values)), + }, + }) await this.saveTeamWorkloadValues(workload) await this.doTeamDeployment( teamId, diff --git a/src/utils/yamlUtils.ts b/src/utils/yamlUtils.ts new file mode 100644 index 00000000..2407e252 --- /dev/null +++ b/src/utils/yamlUtils.ts @@ -0,0 +1,18 @@ +import YAML from 'yaml' + +export function quoteIfDangerous(value: unknown) { + if (typeof value === 'string' && ['yes', 'no', 'on', 'off'].includes(value.toLowerCase())) { + const scalar = new YAML.Scalar(value) + scalar.type = YAML.Scalar.QUOTE_DOUBLE + return scalar + } + return value +} + +export function deepQuote(obj: any): any { + if (Array.isArray(obj)) return obj.map(deepQuote) + if (obj && typeof obj === 'object') { + return Object.fromEntries(Object.entries(obj).map(([k, v]) => [k, deepQuote(v)])) + } + return quoteIfDangerous(obj) +}