Skip to content

Commit

Permalink
chore(override): boilerplate for override pkg and stub functions (#2612)
Browse files Browse the repository at this point in the history
<!-- Provide summary of changes -->
Create `override` pkg and add some stub functions. Part of #2588.
<!-- Issue number, if available. E.g. "Fixes #31", "Addresses #42, 77" -->

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
  • Loading branch information
iamhopaul123 authored Jul 15, 2021
1 parent abece42 commit 092a626
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 0 deletions.
40 changes: 40 additions & 0 deletions internal/pkg/template/override/override.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

// Package override renders the manifest override rules to the CloudFormation template.
package override

import "gopkg.in/yaml.v3"

// CloudFormationTemplate overrides the given CloudFormation template by applying
// the override rules.
func CloudFormationTemplate(overrideRules []Rule, origTemp []byte) ([]byte, error) {
content, err := unmarshalCFNYaml(origTemp)
if err != nil {
return nil, err
}
ruleNodes, err := parseRules(overrideRules)
if err != nil {
return nil, err
}
if err := applyRulesToCFNTemplate(ruleNodes, content); err != nil {
return nil, err
}
output, err := marshalCFNYaml(content)
if err != nil {
return nil, err
}
return output, nil
}

func unmarshalCFNYaml(temp []byte) (*yaml.Node, error) {
return nil, nil
}

func marshalCFNYaml(content *yaml.Node) ([]byte, error) {
return nil, nil
}

func applyRulesToCFNTemplate(rules []*ruleNode, content *yaml.Node) error {
return nil
}
33 changes: 33 additions & 0 deletions internal/pkg/template/override/override_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package override

import (
"testing"

"github.com/stretchr/testify/require"
)

func Test_CloudFormationTemplate(t *testing.T) {
testCases := map[string]struct {
wantedContent string
wantedError error
}{}

for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
// GIVEN

// WHEN
actualContent, err := CloudFormationTemplate(nil, nil)

if tc.wantedError != nil {
require.EqualError(t, err, tc.wantedError.Error())
} else {
require.NoError(t, err)
require.Equal(t, tc.wantedContent, actualContent)
}
})
}
}
38 changes: 38 additions & 0 deletions internal/pkg/template/override/rule.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package override

// Rule is the override rule override package uses.
type Rule struct {
// pathSegment example: "ContainerDefinitions[0].Ulimits.HardLimit: 1024"
// pathSegment string
// value interface{}
}

type ruleNode struct {
// next *ruleNode
}

func parseRules(rules []Rule) ([]*ruleNode, error) {
var ruleNodes []*ruleNode
for _, r := range rules {
if err := r.validate(); err != nil {
return nil, err
}
node, err := r.parse()
if err != nil {
return nil, err
}
ruleNodes = append(ruleNodes, node)
}
return ruleNodes, nil
}

func (r Rule) validate() error {
return nil
}

func (r Rule) parse() (*ruleNode, error) {
return nil, nil
}

0 comments on commit 092a626

Please sign in to comment.