UNPKG

1.85 kBJavaScriptView Raw
1/**
2 * This module overrides the Kes Class
3 * to support specific needs of the Cumulus Deployment.
4 *
5 * Specifically, this module changes the default Kes Deployment in the following ways:
6 *
7 * - Adds a custom handlebar helper for filtering buckets of a certain type
8 * - Adds checking for this.config.params.iam and using it for cloudFormation parameters
9 * intended for the iam deployment
10 *
11 */
12
13'use strict';
14
15const { Kes } = require('kes');
16const Handlebars = require('handlebars');
17
18/**
19 * A subclass of Kes class that overrides parseCF and cloudFormation methods
20 *
21 * @class UpdatedKes
22 */
23class UpdatedKes extends Kes {
24 /**
25 * Overrides the default constructor.
26 * Sets the cf_template_name to have a prefix.
27 *
28 * @param {Object} config - kes config object
29 */
30 constructor(config) {
31 super(config);
32 this.cf_template_name = `iam.${this.cf_template_name}`;
33 this.templateUrl = `https://s3.amazonaws.com/${this.bucket}/${this.stack}/${this.cf_template_name}`;
34 }
35
36 parseCF(cfFile) {
37 Handlebars.registerHelper('BucketIsType', (bucket, type, options) => {
38 const fnTrue = options.fn;
39 const fnFalse = options.inverse;
40 const types = type.split(',');
41
42 if (types.includes(bucket.type)) return fnTrue(bucket);
43
44 return fnFalse(bucket);
45 });
46
47 return super.parseCF(cfFile);
48 }
49
50 /**
51 * Calls CloudFormation's update-stack or create-stack methods
52 * Changed to support multi-template configs by checking for params sub-objects, i.e.:
53 * params:
54 * iam:
55 * - name: someName
56 * value: someValue
57 *
58 * @returns {Promise} returns the promise of an AWS response object
59 */
60 cloudFormation() {
61 if (this.config.iam && this.config.iam.params) this.config.params = this.config.iam.params;
62 return super.cloudFormation();
63 }
64}
65
66module.exports = UpdatedKes;