Skip to content

Commit 8cb00ed

Browse files
feat: add deepQuote for yaml stringify (#801)
Co-authored-by: svcAPLBot <174728082+svcAPLBot@users.noreply.github.com>
1 parent 1690d2d commit 8cb00ed

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
@@ -72,6 +72,7 @@ import {
7272
getValuesSchema,
7373
removeBlankAttributes,
7474
} from 'src/utils'
75+
import { deepQuote } from 'src/utils/yamlUtils'
7576
import {
7677
cleanEnv,
7778
CUSTOM_ROOT_CA,
@@ -1853,9 +1854,11 @@ export default class OtomiStack {
18531854
}
18541855

18551856
async editWorkloadValues(teamId: string, name: string, data: WorkloadValues): Promise<WorkloadValues> {
1856-
const workload = this.repoService
1857-
.getTeamConfigService(teamId)
1858-
.patchWorkload(name, { spec: { values: stringifyYaml(data.values) } })
1857+
const workload = this.repoService.getTeamConfigService(teamId).patchWorkload(name, {
1858+
spec: {
1859+
values: stringifyYaml(deepQuote(data.values)),
1860+
},
1861+
})
18591862
await this.saveTeamWorkloadValues(workload)
18601863
await this.doTeamDeployment(
18611864
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)