forked from external-secrets/kubernetes-external-secrets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
26 lines (21 loc) · 703 Bytes
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const yaml = require('js-yaml')
const parseTemplate = require('lodash/template')
const mapValues = require('lodash/mapValues')
const compileTemplate = (template, data) => parseTemplate(template, { imports: { yaml }, variable: 'data' })(data)
const compileObjectTemplateKeys = (object, data) => {
return mapValues(object, (value) => {
if (value) {
const valueType = typeof value
if (valueType === 'string') {
return compileTemplate(value, data)
} else if (valueType === 'object' && !Array.isArray(value)) {
return compileObjectTemplateKeys(value, data)
}
}
return value
})
}
module.exports = {
compileTemplate,
compileObjectTemplateKeys
}