Skip to content

Commit

Permalink
package: don’t modify non-packageable templates
Browse files Browse the repository at this point in the history
  • Loading branch information
aidansteele committed Jun 18, 2019
1 parent b8218f2 commit bdc0186
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/stackit/cfnyaml/cfnyaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (c *CfnYaml) PackageableNodes() ([]PackageableNode, error) {

if def := packageableDefinition(resType); def != nil {
propNode := valueForKey(valueNode, def.Path...)
if propNode != nil {
if propNode != nil && looksPackageable(propNode, def) {
nodes = append(nodes, PackageableNode{
Name: name,
Value: propNode.Value,
Expand All @@ -86,6 +86,11 @@ func (c *CfnYaml) PackageableNodes() ([]PackageableNode, error) {
return nodes, nil
}

func looksPackageable(n *yaml.Node, def *packageablePropertyDefinition) bool {
// TODO: https://github.com/glassechidna/stackit/issues/34
return n.Kind == yaml.ScalarNode
}

func packageableDefinition(typ string) *packageablePropertyDefinition {
for _, def := range packageablePropertyDefinitions {
if def.ResourceType == typ {
Expand Down
5 changes: 5 additions & 0 deletions pkg/stackit/cfnyaml/cfnyaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ var tests = []tableTestEntry{
"./stack.yml": {"bucket", "key.yml", "abc"},
},
},
{
Name: "f",
Explanation: "no-op",
Replacements: map[string]rewrittenLocation{},
},
}

func TestCfnYaml_PackageableNodes(t *testing.T) {
Expand Down
14 changes: 14 additions & 0 deletions pkg/stackit/cfnyaml/testdata/f_expected.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Transform: AWS::Serverless-2016-10-31
Resources:
Function:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: nodejs8.10
MemorySize: 256
CodeUri:
Bucket: stackit-ap-southeast-2-607481581596
Key: func.zip
Version: GNz4tYuVVvtLYlE5touSEDnp6keZUIDJ
Timeout: 60
AutoPublishAlias: live
14 changes: 14 additions & 0 deletions pkg/stackit/cfnyaml/testdata/f_input.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Transform: AWS::Serverless-2016-10-31
Resources:
Function:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: nodejs8.10
MemorySize: 256
CodeUri:
Bucket: stackit-ap-southeast-2-607481581596
Key: func.zip
Version: GNz4tYuVVvtLYlE5touSEDnp6keZUIDJ
Timeout: 60
AutoPublishAlias: live

0 comments on commit bdc0186

Please sign in to comment.