Skip to content

Commit

Permalink
CR Changes: Fix for function names
Browse files Browse the repository at this point in the history
- getFunctionVersionName and getAliasVersionName function added to utils
  • Loading branch information
Sergii Kovalev authored and Aleksander Dikanski committed May 10, 2019
1 parent 6ac8882 commit b6d106d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/stackops/apiGateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ module.exports = function(currentTemplate, aliasStackTemplates, currentAliasStac
// Adjust permission to reference the function aliases
_.forOwn(apiLambdaPermissions, (permission, name) => {
const functionName = _.replace(name, /LambdaPermissionApiGateway$/, '');
const versionName = _.find(_.keys(versions), version => _.startsWith(version, `${functionName}LambdaVersion`));
const aliasName = _.find(_.keys(aliases), alias => _.startsWith(alias, `${functionName}Alias`));
const versionName = utils.getFunctionVersionName(versions, functionName);
const aliasName = utils.getAliasVersionName(aliases, functionName);
const isExternalRef = isExternalRefAuthorizerPredicate(permission.Properties.FunctionName);

// Adjust references and alias permissions
Expand Down
12 changes: 6 additions & 6 deletions lib/stackops/snsEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ module.exports = function(currentTemplate, aliasStackTemplates, currentAliasStac
_.forOwn(lambdaSubscriptions, subscription => {
const functionNameRef = utils.findAllReferences(_.get(subscription, 'Endpoint'));
const functionName = _.replace(_.get(functionNameRef, '[0].ref', ''), /LambdaFunction$/, '');
const versionName = _.find(_.keys(versions), version => _.startsWith(version, `${functionName}LambdaVersion`));
const aliasName = _.find(_.keys(aliases), alias => _.startsWith(alias, `${functionName}Alias`));
const versionName = utils.getFunctionVersionName(versions, functionName);
const aliasName = utils.getAliasVersionName(aliases, functionName);

subscription.Endpoint = { Ref: aliasName };

Expand All @@ -54,8 +54,8 @@ module.exports = function(currentTemplate, aliasStackTemplates, currentAliasStac

const functionNameRef = utils.findAllReferences(_.get(subscription.Properties, 'Endpoint'));
const functionName = _.replace(_.get(functionNameRef, '[0].ref', ''), /LambdaFunction$/, '');
const versionName = _.find(_.keys(versions), version => _.startsWith(version, `${functionName}LambdaVersion`));
const aliasName = _.find(_.keys(aliases), alias => _.startsWith(alias, `${functionName}Alias`));
const versionName = utils.getFunctionVersionName(versions, functionName);
const aliasName = utils.getAliasVersionName(aliases, functionName);

subscription.Properties.Endpoint = { Ref: aliasName };
subscription.DependsOn = [ versionName, aliasName ];
Expand All @@ -72,8 +72,8 @@ module.exports = function(currentTemplate, aliasStackTemplates, currentAliasStac
// Adjust permission to reference the function aliases
_.forOwn(snsLambdaPermissions, (permission, name) => {
const functionName = _.replace(name, /LambdaPermission.*$/, '');
const versionName = _.find(_.keys(versions), version => _.startsWith(version, `${functionName}LambdaVersion`));
const aliasName = _.find(_.keys(aliases), alias => _.startsWith(alias, `${functionName}Alias`));
const versionName = utils.getFunctionVersionName(versions, functionName);
const aliasName = utils.getAliasVersionName(aliases, functionName);

// Adjust references and alias permissions
permission.Properties.FunctionName = { Ref: aliasName };
Expand Down
17 changes: 17 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,23 @@ class Utils {
return false;
}

/**
* @param {object} versions
* @param {string} functionName
* @returns {string}
*/
static getFunctionVersionName(versions, functionName) {
return _.find(_.keys(versions), version => version === `${functionName}LambdaVersion`);
}

/**
* @param {object} aliases
* @param {string} functionName
* @returns {string}
*/
static getAliasVersionName(aliases, functionName) {
return _.find(_.keys(aliases), alias => alias === `${functionName}Alias`);
}
}

module.exports = Utils;

0 comments on commit b6d106d

Please sign in to comment.