UNPKG

1.35 kBJavaScriptView Raw
1'use strict';
2
3const get = require('lodash.get');
4
5/**
6 * @param {Object} config kes configuration object
7 *
8 */
9function validateWorkflowDefinedLambdas(config) {
10 if (!config.stepFunctions) {
11 return;
12 }
13
14 const lambdaResourceMatch = /\$\{(.*)LambdaFunction\.Arn\}/;
15 const stepFunctions = get(config, 'stepFunctions', {});
16 const stepFunctionStates = Object.values(stepFunctions).map((sf) => Object.values(sf.States));
17 const lambdas = Object.keys(config.lambdas);
18
19 const resources = [].concat(...stepFunctionStates).reduce((result, cfg) => {
20 if (cfg.Type === 'Task') {
21 const lambdaArnMatch = cfg.Resource.match(lambdaResourceMatch);
22 if (lambdaArnMatch && !result.includes(lambdaArnMatch[1])) {
23 result.push(lambdaArnMatch[1]);
24 }
25 }
26 return result;
27 }, []);
28 resources.forEach((resource) => {
29 if (!lambdas.includes(resource)) {
30 console.log(`At failure for ${resource} lambdas was ${lambdas}`);
31 throw new Error(`*** Error: Workflow lambda resource ${resource} not defined in lambda configuration`);
32 }
33 });
34}
35
36/**
37 * Validate deployment configuration.
38 *
39 * @param {Object} config kes configuration object
40 * @throws {Error}
41 */
42function validateConfig(config) {
43 validateWorkflowDefinedLambdas(config);
44}
45
46module.exports = {
47 validateWorkflowDefinedLambdas,
48 validateConfig
49};