This repository has been archived by the owner on Apr 16, 2022. It is now read-only.
Implement Fn::Split, remove cloudformation-js-yaml-schema #148
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import buildYamlSchema, * as yamlSchema from '../yamlSchema'; | ||
import yaml = require('js-yaml'); | ||
import assert = require('assert'); | ||
|
||
describe('yamlSchema', () => { | ||
describe('buildYamlSchema', () => { | ||
it('should build a yaml schema', () => { | ||
assert(buildYamlSchema() instanceof yaml.Schema, 'yamlSchema didn\'t return a yaml schema'); | ||
}) | ||
}); | ||
|
||
describe('functionTag', () => { | ||
it('should work on a Fn::Thing', () => { | ||
assert.strictEqual(yamlSchema.functionTag('Fn::Name'), 'Name'); | ||
}) | ||
it('should work on a Thing', () => { | ||
assert.strictEqual(yamlSchema.functionTag('Name'), 'Name'); | ||
}) | ||
}); | ||
|
||
describe('buildYamlType', () => { | ||
it('should return a type that builds the JSON representation of the yaml tag', () => { | ||
const type = yamlSchema.buildYamlType('Fn::Join', 'sequence'); | ||
const input = ['asdf', 'asdf']; | ||
const representation = type.construct(input); | ||
assert.deepStrictEqual(representation, {'Fn::Join': ['asdf', 'asdf']}); | ||
}); | ||
|
||
it('should special-case Fn::GetAtt', () => { | ||
const type = yamlSchema.buildYamlType('Fn::GetAtt', 'scalar'); | ||
const input = 'Resource.Attribute'; | ||
const representation = type.construct(input); | ||
assert.deepStrictEqual(representation, {'Fn::GetAtt': ['Resource', 'Attribute']}); | ||
}) | ||
}) | ||
|
||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import yaml = require('js-yaml'); | ||
|
||
export function functionTag(functionName: string) { | ||
const splitFunctionName = functionName.split('::'); | ||
return splitFunctionName[splitFunctionName.length-1]; | ||
} | ||
|
||
export default function buildYamlSchema() { | ||
const intrinsicFunctions = require('../data/aws_intrinsic_functions.json'); | ||
const yamlTypes = []; | ||
for (const fn in intrinsicFunctions) { | ||
yamlTypes.push(...buildYamlTypes(fn)); | ||
} | ||
return yaml.Schema.create(yamlTypes); | ||
} | ||
|
||
export type YamlKind = 'scalar' | 'mapping' | 'sequence'; | ||
const kinds: YamlKind[] = ['scalar', 'mapping', 'sequence']; | ||
|
||
export function buildYamlTypes(fnName: string) { | ||
return kinds.map((kind) => buildYamlType(fnName, kind)); | ||
} | ||
|
||
export function buildYamlType(fnName: string, kind: YamlKind) { | ||
const tagName = functionTag(fnName); | ||
const tag = `!${tagName}`; | ||
|
||
const constructFn = (fnName === 'Fn::GetAtt') | ||
? (data: any) => ({'Fn::GetAtt': data.split('.')}) | ||
: (data: any) => ({[fnName]: data}); | ||
|
||
return new yaml.Type(tag, { | ||
kind, | ||
construct: constructFn | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
AWSTemplateFormatVersion: '2010-09-09' | ||
|
||
Resources: | ||
WebServerSecurityGroup: | ||
Type: AWS::EC2::SecurityGroup | ||
Properties: | ||
GroupDescription: Desc | ||
SecurityGroupIngress: | ||
- CidrIp: 0.0.0.0/0 | ||
FromPort: '80' | ||
IpProtocol: tcp | ||
ToPort: '80' | ||
|
||
Outputs: | ||
Simple: | ||
Value: !Split ['-', 'asdf-fdsa'] | ||
Nested: | ||
Value: !Split ['^', !Join ['_', [asdf^fdsa, asdf^fdsa]]] | ||
SelectASplit: | ||
Value: !Select | ||
- 1, | ||
- !Split ['@', 'a@b@c'] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice