Skip to content

Commit 0a3aba6

Browse files
committed
feat: add deepQuote for yaml stringify
1 parent 60def0c commit 0a3aba6

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/otomi-stack.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ import {
6767
getValuesSchema,
6868
removeBlankAttributes,
6969
} from 'src/utils'
70+
import { deepQuote } from 'src/utils/yamlUtils'
7071
import {
7172
cleanEnv,
7273
CUSTOM_ROOT_CA,
@@ -1830,9 +1831,11 @@ export default class OtomiStack {
18301831
}
18311832

18321833
async editWorkloadValues(teamId: string, name: string, data: WorkloadValues): Promise<WorkloadValues> {
1833-
const workload = this.repoService
1834-
.getTeamConfigService(teamId)
1835-
.patchWorkload(name, { spec: { values: stringifyYaml(data.values) } })
1834+
const workload = this.repoService.getTeamConfigService(teamId).patchWorkload(name, {
1835+
spec: {
1836+
values: stringifyYaml(deepQuote(data.values)),
1837+
},
1838+
})
18361839
await this.saveTeamWorkloadValues(workload)
18371840
await this.doTeamDeployment(
18381841
teamId,

src/utils/yamlUtils.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import YAML from 'yaml'
2+
3+
export function quoteIfDangerous(value: unknown) {
4+
if (typeof value === 'string' && ['yes', 'no', 'on', 'off'].includes(value.toLowerCase())) {
5+
const scalar = new YAML.Scalar(value)
6+
scalar.type = YAML.Scalar.QUOTE_DOUBLE
7+
return scalar
8+
}
9+
return value
10+
}
11+
12+
export function deepQuote(obj: any): any {
13+
if (Array.isArray(obj)) return obj.map(deepQuote)
14+
if (obj && typeof obj === 'object') {
15+
return Object.fromEntries(Object.entries(obj).map(([k, v]) => [k, deepQuote(v)]))
16+
}
17+
return quoteIfDangerous(obj)
18+
}

0 commit comments

Comments
 (0)