@znemz/cfn-include 2.0.2 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +17 -3
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -32,9 +32,10 @@ const { isOurExplicitFunction } = require('./lib/schema');
|
|
|
32
32
|
* optional and can be derived from url
|
|
33
33
|
* @param {string} [options.url] '(file|s3):///SOME_FILE_PATH.(json|yaml)'
|
|
34
34
|
* @param {boolean} options.doEnv inject environment from process.env as well
|
|
35
|
+
* @param {boolean} options.doEval allow Fn::Eval to be used (js eval)
|
|
35
36
|
* @param {Object.<string, string>} [options.inject] object to
|
|
36
37
|
* inject { KEY: Value } from where ${KEY}
|
|
37
|
-
* is
|
|
38
|
+
* is substituted with Value
|
|
38
39
|
* @param {boolean} [options.doLog] log all arguments at the include recurse level
|
|
39
40
|
*
|
|
40
41
|
* Example: Load off off file system
|
|
@@ -49,6 +50,9 @@ const { isOurExplicitFunction } = require('./lib/schema');
|
|
|
49
50
|
*/
|
|
50
51
|
module.exports = async function (options) {
|
|
51
52
|
let { template } = options;
|
|
53
|
+
options.doEnv = getBoolEnvOpt(options.doEnv, 'CFN_INCLUDE_DO_ENV');
|
|
54
|
+
options.doEval = getBoolEnvOpt(options.doEval, 'CFN_INCLUDE_DO_EVAL');
|
|
55
|
+
|
|
52
56
|
const base = parseLocation(options.url);
|
|
53
57
|
const scope = options.scope || {};
|
|
54
58
|
if (base.relative) throw new Error('url cannot be relative');
|
|
@@ -232,7 +236,10 @@ async function recurse({ base, scope, cft, ...opts }) {
|
|
|
232
236
|
}
|
|
233
237
|
);
|
|
234
238
|
}
|
|
235
|
-
if (cft['Fn::Eval']
|
|
239
|
+
if (cft['Fn::Eval']) {
|
|
240
|
+
if (!opts.doEval) {
|
|
241
|
+
return Promise.reject(new Error('Fn::Eval is not allowed doEval is falsy'));
|
|
242
|
+
}
|
|
236
243
|
return recurse({ base, scope, cft: cft['Fn::Eval'], ...opts }).then(function (json) {
|
|
237
244
|
// **WARNING** you have now enabled god mode
|
|
238
245
|
// eslint-disable-next-line no-unused-vars, prefer-const
|
|
@@ -387,7 +394,10 @@ async function recurse({ base, scope, cft, ...opts }) {
|
|
|
387
394
|
return isString ? seq.map((i) => String.fromCharCode(i)) : seq;
|
|
388
395
|
}
|
|
389
396
|
|
|
390
|
-
if (cft['Fn::IfEval']
|
|
397
|
+
if (cft['Fn::IfEval']) {
|
|
398
|
+
if (!opts.doEval) {
|
|
399
|
+
return Promise.reject(new Error('Fn::IfEval is not allowed doEval is falsy'));
|
|
400
|
+
}
|
|
391
401
|
return recurse({ base, scope, cft: cft['Fn::IfEval'], ...opts }).then(function (json) {
|
|
392
402
|
// eslint-disable-next-line prefer-const
|
|
393
403
|
let { truthy, falsy, evalCond, inject, doLog } = json;
|
|
@@ -718,3 +728,7 @@ function JSONifyString(string) {
|
|
|
718
728
|
});
|
|
719
729
|
return lines;
|
|
720
730
|
}
|
|
731
|
+
|
|
732
|
+
function getBoolEnvOpt(opt, envKey) {
|
|
733
|
+
return process.env[envKey] ? !!process.env[envKey] : opt;
|
|
734
|
+
}
|