Skip to content

Commit

Permalink
Merge branch 'release/v2.5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
svdgraaf committed Oct 7, 2019
2 parents 9489f2b + ec7adec commit aab5739
Show file tree
Hide file tree
Showing 6 changed files with 1,836 additions and 2,440 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Sander van de Graaf

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,15 @@ custom:
pseudoParameters:
allowReferences: false
```

Escaping tokens
-----------------------------------
You can prevent tokens from being replaced by escaping with the `@` character after the token's hash character
```yaml
DynamoDBInputS3OutputHive:
Type: AWS::DataPipeline::Pipeline
Properties:
PipelineObjects:
- Key: "directoryPath"
StringValue: "#@{myOutputS3Loc}/#@{format(@scheduledStartTime, 'YYYY-MM-dd-HH-mm-ss')}"
```
7 changes: 7 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ class ServerlessAWSPseudoParameters {
}
}


var escaped_regex = /#@{([^}]+)}/g;
if (typeof value === 'string' && value.search(escaped_regex) >= 0) {
let replacedString = value.replace(escaped_regex, '#{$1}');
dictionary[key] = replacedString;
}

// dicts and arrays need to be looped through
if (isDict(value) || isArray(value)) {
dictionary[key] = replaceChildNodes(value, name + '::' + key);
Expand Down
11 changes: 8 additions & 3 deletions lib/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ describe('Plugin', () => {
Reference: "#{SomeResource}",
Substitution: {
"Fn::Sub": "#{SomeResource}"
},
Escaping: {
StringValue: "#@{myOutputS3Loc}/#@{format(@scheduledStartTime, 'YYYY-MM-dd-HH-mm-ss')}"
}
}
}
Expand All @@ -41,11 +44,11 @@ describe('Plugin', () => {
serverlessPseudoParamsPlugin.serverless.service.service = 'foo-service';
serverlessPseudoParamsPlugin.addParameters();
resultTemplate = serverlessPseudoParamsPlugin.serverless.service.provider.compiledCloudFormationTemplate;
expect(Object.keys(resultTemplate.Resources.acmeResource.Properties).length).toEqual(10);
expect(Object.keys(resultTemplate.Resources.acmeResource.Properties).length).toEqual(11);
});

it('replaces #{AWS::[VAR]} with the correct CF pseudo parameter', () => {
expect(Object.keys(resultTemplate.Resources.acmeResource.Properties).length).toEqual(10);
expect(Object.keys(resultTemplate.Resources.acmeResource.Properties).length).toEqual(11);
});

it('replaces #{AWS::AccountId} with the ${AWS::AccountId} pseudo parameter', () => {
Expand Down Expand Up @@ -78,7 +81,9 @@ describe('Plugin', () => {
it('should not add Fn::Sub to items with Fn::Sub already', () => {
expect(resultTemplate.Resources.acmeResource.Properties.Substitution).toEqual({ 'Fn::Sub': '${SomeResource}'});
});

it('should not replace escaped items', () => {
expect(resultTemplate.Resources.acmeResource.Properties.Escaping).toEqual({ 'StringValue': '#{myOutputS3Loc}/#{format(@scheduledStartTime, \'YYYY-MM-dd-HH-mm-ss\')}'});
});
});

describe('Using pseudo parameters with allowReferences', () => {
Expand Down
Loading

0 comments on commit aab5739

Please sign in to comment.