File tree Expand file tree Collapse file tree 3 files changed +111
-0
lines changed
internal/pkg/template/override Expand file tree Collapse file tree 3 files changed +111
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments