Skip to content

Commit 092a626

Browse files
authored
chore(override): boilerplate for override pkg and stub functions (#2612)
<!-- 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.
1 parent abece42 commit 092a626

File tree

3 files changed

+111
-0
lines changed

3 files changed

+111
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
// Package override renders the manifest override rules to the CloudFormation template.
5+
package override
6+
7+
import "gopkg.in/yaml.v3"
8+
9+
// CloudFormationTemplate overrides the given CloudFormation template by applying
10+
// the override rules.
11+
func CloudFormationTemplate(overrideRules []Rule, origTemp []byte) ([]byte, error) {
12+
content, err := unmarshalCFNYaml(origTemp)
13+
if err != nil {
14+
return nil, err
15+
}
16+
ruleNodes, err := parseRules(overrideRules)
17+
if err != nil {
18+
return nil, err
19+
}
20+
if err := applyRulesToCFNTemplate(ruleNodes, content); err != nil {
21+
return nil, err
22+
}
23+
output, err := marshalCFNYaml(content)
24+
if err != nil {
25+
return nil, err
26+
}
27+
return output, nil
28+
}
29+
30+
func unmarshalCFNYaml(temp []byte) (*yaml.Node, error) {
31+
return nil, nil
32+
}
33+
34+
func marshalCFNYaml(content *yaml.Node) ([]byte, error) {
35+
return nil, nil
36+
}
37+
38+
func applyRulesToCFNTemplate(rules []*ruleNode, content *yaml.Node) error {
39+
return nil
40+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package override
5+
6+
import (
7+
"testing"
8+
9+
"github.com/stretchr/testify/require"
10+
)
11+
12+
func Test_CloudFormationTemplate(t *testing.T) {
13+
testCases := map[string]struct {
14+
wantedContent string
15+
wantedError error
16+
}{}
17+
18+
for name, tc := range testCases {
19+
t.Run(name, func(t *testing.T) {
20+
// GIVEN
21+
22+
// WHEN
23+
actualContent, err := CloudFormationTemplate(nil, nil)
24+
25+
if tc.wantedError != nil {
26+
require.EqualError(t, err, tc.wantedError.Error())
27+
} else {
28+
require.NoError(t, err)
29+
require.Equal(t, tc.wantedContent, actualContent)
30+
}
31+
})
32+
}
33+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package override
5+
6+
// Rule is the override rule override package uses.
7+
type Rule struct {
8+
// pathSegment example: "ContainerDefinitions[0].Ulimits.HardLimit: 1024"
9+
// pathSegment string
10+
// value interface{}
11+
}
12+
13+
type ruleNode struct {
14+
// next *ruleNode
15+
}
16+
17+
func parseRules(rules []Rule) ([]*ruleNode, error) {
18+
var ruleNodes []*ruleNode
19+
for _, r := range rules {
20+
if err := r.validate(); err != nil {
21+
return nil, err
22+
}
23+
node, err := r.parse()
24+
if err != nil {
25+
return nil, err
26+
}
27+
ruleNodes = append(ruleNodes, node)
28+
}
29+
return ruleNodes, nil
30+
}
31+
32+
func (r Rule) validate() error {
33+
return nil
34+
}
35+
36+
func (r Rule) parse() (*ruleNode, error) {
37+
return nil, nil
38+
}

0 commit comments

Comments
 (0)