@znemz/cfn-include 2.1.2 → 2.1.4
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/bin/cli.js +9 -9
- package/index.js +39 -39
- package/lib/cfnclient.js +5 -5
- package/lib/include/api.js +3 -4
- package/lib/promise.js +1 -1
- package/package.json +15 -16
package/bin/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
const exec = require('child_process').execSync;
|
|
4
4
|
const path = require('path');
|
|
5
5
|
const _ = require('lodash');
|
|
@@ -15,14 +15,14 @@ const replaceEnv = require('../lib/replaceEnv');
|
|
|
15
15
|
yargs.version(false);
|
|
16
16
|
|
|
17
17
|
const { env } = process;
|
|
18
|
-
|
|
18
|
+
|
|
19
19
|
const opts = yargs
|
|
20
20
|
.command('$0 [path] [options]', pkg.description, (y) =>
|
|
21
21
|
y.positional('path', {
|
|
22
22
|
positional: true,
|
|
23
23
|
desc: 'location of template. Either path to a local file, URL or file on an S3 bucket (e.g. s3://bucket-name/example.template)',
|
|
24
24
|
required: false,
|
|
25
|
-
})
|
|
25
|
+
}),
|
|
26
26
|
)
|
|
27
27
|
.options({
|
|
28
28
|
minimize: {
|
|
@@ -59,7 +59,7 @@ const opts = yargs
|
|
|
59
59
|
},
|
|
60
60
|
context: {
|
|
61
61
|
desc:
|
|
62
|
-
|
|
62
|
+
|
|
63
63
|
'template full path. only utilized for stdin when the template is piped to this script',
|
|
64
64
|
required: false,
|
|
65
65
|
string: true,
|
|
@@ -77,13 +77,13 @@ const opts = yargs
|
|
|
77
77
|
inject: {
|
|
78
78
|
alias: 'i',
|
|
79
79
|
string: true,
|
|
80
|
-
|
|
80
|
+
|
|
81
81
|
desc: `JSON string payload to use for template injection.`,
|
|
82
82
|
coerce: (valStr) => JSON.parse(valStr),
|
|
83
83
|
},
|
|
84
84
|
doLog: {
|
|
85
85
|
boolean: true,
|
|
86
|
-
|
|
86
|
+
|
|
87
87
|
desc: `console log out include options in recurse step`,
|
|
88
88
|
},
|
|
89
89
|
version: {
|
|
@@ -154,8 +154,8 @@ promise
|
|
|
154
154
|
})
|
|
155
155
|
.toString()
|
|
156
156
|
.trim();
|
|
157
|
-
} catch
|
|
158
|
-
|
|
157
|
+
} catch {
|
|
158
|
+
|
|
159
159
|
}
|
|
160
160
|
_.defaultsDeep(template, {
|
|
161
161
|
Metadata: {
|
|
@@ -180,7 +180,7 @@ promise
|
|
|
180
180
|
console.log(
|
|
181
181
|
opts.yaml
|
|
182
182
|
? yaml.dump(template, opts)
|
|
183
|
-
: JSON.stringify(template, null, opts.minimize ? null : 2)
|
|
183
|
+
: JSON.stringify(template, null, opts.minimize ? null : 2),
|
|
184
184
|
);
|
|
185
185
|
})
|
|
186
186
|
.catch(function (err) {
|
package/index.js
CHANGED
|
@@ -92,7 +92,7 @@ module.exports = async function (options) {
|
|
|
92
92
|
*/
|
|
93
93
|
async function recurse({ base, scope, cft, ...opts }) {
|
|
94
94
|
if (opts.doLog) {
|
|
95
|
-
|
|
95
|
+
|
|
96
96
|
console.log({ base, scope, cft, ...opts });
|
|
97
97
|
}
|
|
98
98
|
scope = _.clone(scope);
|
|
@@ -168,7 +168,7 @@ async function recurse({ base, scope, cft, ...opts }) {
|
|
|
168
168
|
return recurse({ base, scope, cft: cft['Fn::FlattenDeep'], ...opts }).then(
|
|
169
169
|
function (json) {
|
|
170
170
|
return _.flattenDeep(json);
|
|
171
|
-
}
|
|
171
|
+
},
|
|
172
172
|
);
|
|
173
173
|
}
|
|
174
174
|
if (cft['Fn::Uniq']) {
|
|
@@ -195,7 +195,7 @@ async function recurse({ base, scope, cft, ...opts }) {
|
|
|
195
195
|
return recurse({ base, scope, cft: cft['Fn::SortedUniq'], ...opts }).then(
|
|
196
196
|
function (array) {
|
|
197
197
|
return _.sortedUniq(array.sort());
|
|
198
|
-
}
|
|
198
|
+
},
|
|
199
199
|
);
|
|
200
200
|
}
|
|
201
201
|
if (cft['Fn::SortBy']) {
|
|
@@ -208,7 +208,7 @@ async function recurse({ base, scope, cft, ...opts }) {
|
|
|
208
208
|
}
|
|
209
209
|
if (cft['Fn::SortObject']) {
|
|
210
210
|
return recurse({ base, scope, cft: cft['Fn::SortObject'], ...opts }).then(function ({
|
|
211
|
-
|
|
211
|
+
|
|
212
212
|
object,
|
|
213
213
|
options,
|
|
214
214
|
...rest // allow object to be optional (implied)
|
|
@@ -233,7 +233,7 @@ async function recurse({ base, scope, cft, ...opts }) {
|
|
|
233
233
|
function (json) {
|
|
234
234
|
// omit falsy values except false, and 0
|
|
235
235
|
return _.omitBy(json, (v) => !v && v !== false && v !== 0);
|
|
236
|
-
}
|
|
236
|
+
},
|
|
237
237
|
);
|
|
238
238
|
}
|
|
239
239
|
if (cft['Fn::Eval']) {
|
|
@@ -242,14 +242,14 @@ async function recurse({ base, scope, cft, ...opts }) {
|
|
|
242
242
|
}
|
|
243
243
|
return recurse({ base, scope, cft: cft['Fn::Eval'], ...opts }).then(function (json) {
|
|
244
244
|
// **WARNING** you have now enabled god mode
|
|
245
|
-
|
|
245
|
+
|
|
246
246
|
let { state, script, inject, doLog } = json;
|
|
247
247
|
script = replaceEnv(script, _.merge(_.cloneDeep(opts.inject), inject), opts.doEnv);
|
|
248
248
|
if (doLog) {
|
|
249
|
-
|
|
249
|
+
|
|
250
250
|
console.log({ state, script, inject });
|
|
251
251
|
}
|
|
252
|
-
|
|
252
|
+
|
|
253
253
|
return eval(script);
|
|
254
254
|
});
|
|
255
255
|
}
|
|
@@ -258,7 +258,7 @@ async function recurse({ base, scope, cft, ...opts }) {
|
|
|
258
258
|
function (json) {
|
|
259
259
|
json = _.isPlainObject(json) ? { ...json } : { location: json };
|
|
260
260
|
if (json.doLog) {
|
|
261
|
-
|
|
261
|
+
|
|
262
262
|
console.log(json);
|
|
263
263
|
}
|
|
264
264
|
const location = parseLocation(json.location);
|
|
@@ -277,13 +277,13 @@ async function recurse({ base, scope, cft, ...opts }) {
|
|
|
277
277
|
return globs;
|
|
278
278
|
}
|
|
279
279
|
return 'Unsupported File Type';
|
|
280
|
-
}
|
|
280
|
+
},
|
|
281
281
|
);
|
|
282
282
|
}
|
|
283
283
|
if (cft['Fn::Merge']) {
|
|
284
284
|
return recurse({ base, scope, cft: cft['Fn::Merge'], ...opts }).then(function (json) {
|
|
285
285
|
delete cft['Fn::Merge'];
|
|
286
|
-
|
|
286
|
+
|
|
287
287
|
return recurse({ base, scope, cft: _.defaults(cft, _.merge.apply(_, json)), ...opts });
|
|
288
288
|
});
|
|
289
289
|
}
|
|
@@ -298,24 +298,24 @@ async function recurse({ base, scope, cft, ...opts }) {
|
|
|
298
298
|
});
|
|
299
299
|
}
|
|
300
300
|
return recurse({ base, scope, cft: _.defaults(cft, mergedObj), ...opts });
|
|
301
|
-
}
|
|
301
|
+
},
|
|
302
302
|
);
|
|
303
303
|
}
|
|
304
304
|
if (cft['Fn::ObjectKeys']) {
|
|
305
305
|
return recurse({ base, scope, cft: cft['Fn::ObjectKeys'], ...opts }).then((json) =>
|
|
306
|
-
Object.keys(json)
|
|
306
|
+
Object.keys(json),
|
|
307
307
|
);
|
|
308
308
|
}
|
|
309
309
|
if (cft['Fn::ObjectValues']) {
|
|
310
310
|
return recurse({ base, scope, cft: cft['Fn::ObjectValues'], ...opts }).then((json) =>
|
|
311
|
-
Object.values(json)
|
|
311
|
+
Object.values(json),
|
|
312
312
|
);
|
|
313
313
|
}
|
|
314
314
|
if (cft['Fn::Stringify']) {
|
|
315
315
|
return recurse({ base, scope, cft: cft['Fn::Stringify'], ...opts }).then(
|
|
316
316
|
function (json) {
|
|
317
317
|
return JSON.stringify(json);
|
|
318
|
-
}
|
|
318
|
+
},
|
|
319
319
|
);
|
|
320
320
|
}
|
|
321
321
|
if (cft['Fn::StringSplit']) {
|
|
@@ -324,13 +324,13 @@ async function recurse({ base, scope, cft, ...opts }) {
|
|
|
324
324
|
if (!string) {
|
|
325
325
|
string = '';
|
|
326
326
|
}
|
|
327
|
-
|
|
327
|
+
|
|
328
328
|
if (doLog) console.log({ string, separator });
|
|
329
329
|
if (!separator) {
|
|
330
330
|
separator = ',';
|
|
331
331
|
}
|
|
332
332
|
return string.split(separator);
|
|
333
|
-
}
|
|
333
|
+
},
|
|
334
334
|
);
|
|
335
335
|
}
|
|
336
336
|
if (cft['Fn::UpperCamelCase']) {
|
|
@@ -356,7 +356,7 @@ async function recurse({ base, scope, cft, ...opts }) {
|
|
|
356
356
|
if (cft['Fn::Outputs']) {
|
|
357
357
|
const outputs = await recurse({ base, scope, cft: cft['Fn::Outputs'], ...opts });
|
|
358
358
|
const result = {};
|
|
359
|
-
|
|
359
|
+
|
|
360
360
|
for (const output in outputs) {
|
|
361
361
|
const val = outputs[output];
|
|
362
362
|
const exp = {
|
|
@@ -380,7 +380,7 @@ async function recurse({ base, scope, cft, ...opts }) {
|
|
|
380
380
|
|
|
381
381
|
if (cft['Fn::Sequence']) {
|
|
382
382
|
const outputs = await recurse({ base, scope, cft: cft['Fn::Sequence'], ...opts });
|
|
383
|
-
|
|
383
|
+
|
|
384
384
|
let [start, stop, step = 1] = outputs;
|
|
385
385
|
const isString = typeof start === 'string';
|
|
386
386
|
if (isString) {
|
|
@@ -389,7 +389,7 @@ async function recurse({ base, scope, cft, ...opts }) {
|
|
|
389
389
|
}
|
|
390
390
|
const seq = Array.from(
|
|
391
391
|
{ length: Math.floor((stop - start) / step) + 1 },
|
|
392
|
-
(__, i) => start + i * step
|
|
392
|
+
(__, i) => start + i * step,
|
|
393
393
|
);
|
|
394
394
|
return isString ? seq.map((i) => String.fromCharCode(i)) : seq;
|
|
395
395
|
}
|
|
@@ -399,7 +399,7 @@ async function recurse({ base, scope, cft, ...opts }) {
|
|
|
399
399
|
return Promise.reject(new Error('Fn::IfEval is not allowed doEval is falsy'));
|
|
400
400
|
}
|
|
401
401
|
return recurse({ base, scope, cft: cft['Fn::IfEval'], ...opts }).then(function (json) {
|
|
402
|
-
|
|
402
|
+
|
|
403
403
|
let { truthy, falsy, evalCond, inject, doLog } = json;
|
|
404
404
|
if (!evalCond) {
|
|
405
405
|
return Promise.reject(new Error('Fn::IfEval evalCond is required'));
|
|
@@ -418,11 +418,11 @@ async function recurse({ base, scope, cft, ...opts }) {
|
|
|
418
418
|
falsy = replaceEnv(falsy, _.merge(_.cloneDeep(opts.inject), inject), opts.doEnv);
|
|
419
419
|
}
|
|
420
420
|
|
|
421
|
-
|
|
421
|
+
|
|
422
422
|
const condResult = eval(evalCond);
|
|
423
423
|
|
|
424
424
|
if (doLog) {
|
|
425
|
-
|
|
425
|
+
|
|
426
426
|
console.log({ truthy, falsy, inject, evalCond, condResult });
|
|
427
427
|
}
|
|
428
428
|
|
|
@@ -456,11 +456,11 @@ async function recurse({ base, scope, cft, ...opts }) {
|
|
|
456
456
|
Tags: tags,
|
|
457
457
|
},
|
|
458
458
|
},
|
|
459
|
-
val
|
|
459
|
+
val,
|
|
460
460
|
);
|
|
461
461
|
}
|
|
462
462
|
return resources[id];
|
|
463
|
-
})
|
|
463
|
+
}),
|
|
464
464
|
);
|
|
465
465
|
});
|
|
466
466
|
return Promise.all(promises).then(() => resources);
|
|
@@ -468,7 +468,7 @@ async function recurse({ base, scope, cft, ...opts }) {
|
|
|
468
468
|
}
|
|
469
469
|
|
|
470
470
|
return Promise.props(
|
|
471
|
-
_.mapValues(cft, (template) => recurse({ base, scope, cft: template, ...opts }))
|
|
471
|
+
_.mapValues(cft, (template) => recurse({ base, scope, cft: template, ...opts })),
|
|
472
472
|
);
|
|
473
473
|
}
|
|
474
474
|
|
|
@@ -573,7 +573,7 @@ async function fnInclude({ base, scope, cft, ...opts }) {
|
|
|
573
573
|
const inject = await recurse({ base, scope, cft: cft.inject, ...opts });
|
|
574
574
|
const processed = await origProcTemplate(template, inject, opts.doEnv);
|
|
575
575
|
return replaceEnv(processed, inject, opts.doEnv);
|
|
576
|
-
} catch
|
|
576
|
+
} catch {
|
|
577
577
|
return '';
|
|
578
578
|
}
|
|
579
579
|
};
|
|
@@ -583,7 +583,7 @@ async function fnInclude({ base, scope, cft, ...opts }) {
|
|
|
583
583
|
cft = fnIncludeOpts(cft, opts);
|
|
584
584
|
|
|
585
585
|
if (cft.doLog) {
|
|
586
|
-
|
|
586
|
+
|
|
587
587
|
console.log({ base, scope, args: cft, ...opts });
|
|
588
588
|
}
|
|
589
589
|
// console.log(args)
|
|
@@ -610,7 +610,7 @@ async function fnInclude({ base, scope, cft, ...opts }) {
|
|
|
610
610
|
} else if (location.protocol === 's3') {
|
|
611
611
|
const basedir = pathParse(base.path).dir;
|
|
612
612
|
const bucket = location.relative ? base.host : location.host;
|
|
613
|
-
|
|
613
|
+
|
|
614
614
|
let key = location.relative ? url.resolve(`${basedir}/`, location.raw) : location.path;
|
|
615
615
|
key = key.replace(/^\//, '');
|
|
616
616
|
absolute = `${location.protocol}://${[bucket, key].join('/')}`;
|
|
@@ -619,17 +619,17 @@ async function fnInclude({ base, scope, cft, ...opts }) {
|
|
|
619
619
|
new GetObjectCommand({
|
|
620
620
|
Bucket: bucket,
|
|
621
621
|
Key: key,
|
|
622
|
-
})
|
|
622
|
+
}),
|
|
623
623
|
)
|
|
624
624
|
.then((res) => res.Body.toString())
|
|
625
625
|
.then(procTemplate);
|
|
626
626
|
} else if (location.protocol && location.protocol.match(/^https?$/)) {
|
|
627
627
|
const basepath = `${pathParse(base.path).dir}/`;
|
|
628
|
-
|
|
628
|
+
|
|
629
629
|
absolute = location.relative
|
|
630
630
|
? url.resolve(`${location.protocol}://${base.host}${basepath}`, location.raw)
|
|
631
631
|
: location.raw;
|
|
632
|
-
|
|
632
|
+
|
|
633
633
|
body = request(absolute).then(procTemplate);
|
|
634
634
|
}
|
|
635
635
|
return handleIncludeBody({ scope, args: cft, body, absolute });
|
|
@@ -678,13 +678,13 @@ async function handleIncludeBody({ scope, args, body, absolute }) {
|
|
|
678
678
|
const query = _.isString(args.query)
|
|
679
679
|
? replaceEnv(args.query, args.inject, args.doEnv)
|
|
680
680
|
: await recurse({
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
681
|
+
base: parseLocation(absolute),
|
|
682
|
+
scope,
|
|
683
|
+
cft: args.query,
|
|
684
|
+
doEnv: args.doEnv,
|
|
685
|
+
doLog: args.doLog,
|
|
686
|
+
inject: args.inject,
|
|
687
|
+
});
|
|
688
688
|
return getParser(args.parser)(temp, query);
|
|
689
689
|
});
|
|
690
690
|
}
|
package/lib/cfnclient.js
CHANGED
|
@@ -35,7 +35,7 @@ class Client {
|
|
|
35
35
|
Body: tpl,
|
|
36
36
|
Bucket: this.bucket,
|
|
37
37
|
Key: key,
|
|
38
|
-
})
|
|
38
|
+
}),
|
|
39
39
|
);
|
|
40
40
|
|
|
41
41
|
let res, err;
|
|
@@ -49,7 +49,7 @@ class Client {
|
|
|
49
49
|
new DeleteObjectCommand({
|
|
50
50
|
Bucket: this.bucket,
|
|
51
51
|
Key: key,
|
|
52
|
-
})
|
|
52
|
+
}),
|
|
53
53
|
)
|
|
54
54
|
.catch(() => {});
|
|
55
55
|
if (err) throw err;
|
|
@@ -70,16 +70,16 @@ class Client {
|
|
|
70
70
|
.send(
|
|
71
71
|
new ValidateTemplateCommand({
|
|
72
72
|
TemplateURL: `https://s3.${this.region}.amazonaws.com/${this.bucket}/${key}`,
|
|
73
|
-
})
|
|
73
|
+
}),
|
|
74
74
|
)
|
|
75
|
-
.promise()
|
|
75
|
+
.promise(),
|
|
76
76
|
);
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
return this.client.send(
|
|
80
80
|
new ValidateTemplateCommand({
|
|
81
81
|
TemplateBody: tpl,
|
|
82
|
-
})
|
|
82
|
+
}),
|
|
83
83
|
);
|
|
84
84
|
}
|
|
85
85
|
}
|
package/lib/include/api.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
AWS = require('aws-sdk-proxy'),
|
|
1
|
+
let AWS = require('aws-sdk-proxy'),
|
|
3
2
|
jmespath = require('jmespath');
|
|
4
3
|
|
|
5
|
-
module.exports = function(args) {
|
|
4
|
+
module.exports = function (args) {
|
|
6
5
|
var service = new AWS[args.service](args.region ? { region: args.region } : null);
|
|
7
|
-
return service[args.action](args.parameters ? args.parameters : {}).promise().then(function(res) {
|
|
6
|
+
return service[args.action](args.parameters ? args.parameters : {}).promise().then(function (res) {
|
|
8
7
|
return args.query ? jmespath.search(res, args.query) : res;
|
|
9
8
|
});
|
|
10
9
|
}
|
package/lib/promise.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@znemz/cfn-include",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.4",
|
|
4
4
|
"description": "Preprocessor for CloudFormation templates with support for loops and flexible include statements",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"aws",
|
|
@@ -43,36 +43,35 @@
|
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@aws-sdk/client-cloudformation": "^3.637.0",
|
|
45
45
|
"@aws-sdk/client-s3": "^3.637.0",
|
|
46
|
-
"@znemz/cft-utils": "0.1.
|
|
46
|
+
"@znemz/cft-utils": "0.1.19",
|
|
47
47
|
"@znemz/sort-object": "^3.0.4",
|
|
48
|
-
"aws-sdk-v3-proxy": "2.
|
|
48
|
+
"aws-sdk-v3-proxy": "2.2.0",
|
|
49
49
|
"bluebird": "^3.7.2",
|
|
50
50
|
"deepmerge": "^4.2.2",
|
|
51
51
|
"glob": "^11.0.1",
|
|
52
52
|
"jmespath": "^0.16.0",
|
|
53
|
-
"js-yaml": "^3.14.
|
|
53
|
+
"js-yaml": "^3.14.1",
|
|
54
54
|
"jsonminify": "^0.4.1",
|
|
55
55
|
"lodash": "^4.17.21",
|
|
56
56
|
"path-parse": "~1.0.7",
|
|
57
|
-
"proxy-agent": "6.
|
|
58
|
-
"yargs": "17"
|
|
57
|
+
"proxy-agent": "6.5.0",
|
|
58
|
+
"yargs": "~17.7.2"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
|
-
"@commitlint/cli": "^
|
|
62
|
-
"@commitlint/config-conventional": "^
|
|
63
|
-
"better-npm-audit": "3.
|
|
61
|
+
"@commitlint/cli": "^20",
|
|
62
|
+
"@commitlint/config-conventional": "^20",
|
|
63
|
+
"better-npm-audit": "3.11.0",
|
|
64
64
|
"commit-and-tag-version": "12",
|
|
65
|
-
"commitlint": "
|
|
66
|
-
"eslint": "
|
|
65
|
+
"commitlint": "20",
|
|
66
|
+
"eslint": "9",
|
|
67
67
|
"eslint-config-prettier": "10",
|
|
68
|
-
"eslint-
|
|
69
|
-
"eslint-plugin-mocha": "10",
|
|
68
|
+
"eslint-plugin-mocha": "11",
|
|
70
69
|
"eslint-plugin-prettier": "5",
|
|
71
|
-
"mocha": "
|
|
70
|
+
"mocha": "11.7.2",
|
|
72
71
|
"npm-run-all": "4.1.5",
|
|
73
72
|
"prettier": "3",
|
|
74
|
-
"serve": "14.2.
|
|
75
|
-
"sort-package-json": "3.
|
|
73
|
+
"serve": "14.2.5",
|
|
74
|
+
"sort-package-json": "3.4.0"
|
|
76
75
|
},
|
|
77
76
|
"originalAuthor": {
|
|
78
77
|
"name": "Moritz Onken",
|