Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

serverless-pseudo-parameters

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

serverless-pseudo-parameters - npm Package Compare versions

Comparing version 1.5.0 to 1.6.0

42

lib/index.js

@@ -11,2 +11,3 @@ 'use strict';

this.skipRegionReplace = get(serverless.service, 'custom.pseudoParameters.skipRegionReplace', false)
this.allowReferences = get(serverless.service, 'custom.pseudoParameters.allowReferences', false)
}

@@ -18,2 +19,3 @@

const skipRegionReplace = this.skipRegionReplace;
const allowReferences = this.allowReferences;
const consoleLog = this.serverless.cli.consoleLog;

@@ -44,12 +46,17 @@

return [
'eu-west-1',
'eu-west-2',
'us-east-1',
'us-east-2',
'us-west-2',
'ap-south-1',
'ap-northeast-2',
'ap-southeast-2',
'ap-northeast-1',
'eu-central-1'
"ap-northeast-1",
"ap-northeast-2",
"ap-south-1",
"ap-southeast-1",
"ap-southeast-2",
"ca-central-1",
"eu-central-1",
"eu-west-1",
"eu-west-2",
"eu-west-3",
"sa-east-1",
"us-east-1",
"us-east-2",
"us-west-1",
"us-west-2"
]

@@ -72,8 +79,13 @@ }

var aws_regex;
if (allowReferences) {
aws_regex = /#{([^}]+)}/g;
} else {
aws_regex = /#{(AWS::[a-zA-Z]+)}/g
}
// we only want to possibly replace strings with an Fn::Sub
if (typeof value === 'string' && value.search(/#{AWS::([a-zA-Z]+)}/) >= 0) {
const aws_regex = /#{AWS::([a-zA-Z]+)}/g;
if (typeof value === 'string' && value.search(aws_regex) >= 0) {
dictionary[key] = {
"Fn::Sub": value.replace(aws_regex, '${AWS::$1}')
"Fn::Sub": value.replace(aws_regex, '${$1}')
};

@@ -84,3 +96,3 @@

while (m) {
consoleLog('AWS Pseudo Parameter: ' + name + '::' + key + ' Replaced ' + yellow(m[1]) + ' with ' + yellow('${AWS::' + m[1] + '}'));
consoleLog('AWS Pseudo Parameter: ' + name + '::' + key + ' Replaced ' + yellow(m[1]) + ' with ' + yellow('${' + m[1] + '}'));
m = aws_regex.exec(value);

@@ -87,0 +99,0 @@ }

@@ -33,2 +33,3 @@ const Plugin = require('.');

URLSuffix: "#{AWS::URLSuffix}",
Reference: "#{SomeResource}",
}

@@ -41,7 +42,7 @@ }

resultTemplate = serverlessPseudoParamsPlugin.serverless.service.provider.compiledCloudFormationTemplate;
expect(Object.keys(resultTemplate.Resources.acmeResource.Properties).length).toEqual(8);
expect(Object.keys(resultTemplate.Resources.acmeResource.Properties).length).toEqual(9);
});
it('replaces #{AWS::[VAR]} with the correct CF pseudo parameter', () => {
expect(Object.keys(resultTemplate.Resources.acmeResource.Properties).length).toEqual(8);
expect(Object.keys(resultTemplate.Resources.acmeResource.Properties).length).toEqual(9);
});

@@ -73,5 +74,58 @@

});
it('does not replace #{SomeResource}', () => {
expect(resultTemplate.Resources.acmeResource.Properties.Reference).toEqual("#{SomeResource}");
});
});
describe('Using pseudo parameters with allowReferences', () => {
let serverlessPseudoParamsPlugin;
let resultTemplate;
beforeEach(() => {
const serverless = {
cli: {
log: () => {},
consoleLog: () => {}
},
service: {
provider: {
compiledCloudFormationTemplate: {},
},
custom: {
pseudoParameters: {
allowReferences: true
}
}
},
};
serverless.service.provider.compiledCloudFormationTemplate = { Resources: {
acmeResource: {
Type: "AWS::Foo::Bar",
Properties: {
AccountId: "#{AWS::AccountId}",
Reference: "#{SomeResource}",
}
}
} };
serverlessPseudoParamsPlugin = new Plugin(serverless);
serverlessPseudoParamsPlugin.serverless.service.service = 'foo-service';
serverlessPseudoParamsPlugin.addParameters();
resultTemplate = serverlessPseudoParamsPlugin.serverless.service.provider.compiledCloudFormationTemplate;
expect(Object.keys(resultTemplate.Resources.acmeResource.Properties).length).toEqual(2);
});
it('replaces #{AWS::[VAR]} with the correct CF pseudo parameter', () => {
expect(Object.keys(resultTemplate.Resources.acmeResource.Properties).length).toEqual(2);
});
it('replaces #{AWS::AccountId} with the ${AWS::AccountId} pseudo parameter', () => {
expect(resultTemplate.Resources.acmeResource.Properties.AccountId).toEqual({ 'Fn::Sub': '${AWS::AccountId}' });
});
it('replaces #{SomeResource} with ${SomeResource}', () => {
expect(resultTemplate.Resources.acmeResource.Properties.Reference).toEqual({ 'Fn::Sub': '${SomeResource}' });
});
});
describe('using pseudo parameters in the outputs', () => {

@@ -78,0 +132,0 @@ let serverlessPseudoParamsPlugin;

{
"name": "serverless-pseudo-parameters",
"version": "1.5.0",
"version": "1.6.0",
"devDependencies": {

@@ -5,0 +5,0 @@ "jest": "^22.4.2"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc