-
Notifications
You must be signed in to change notification settings - Fork 414
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
1 parent
abece42
commit 092a626
Showing
3 changed files
with
111 additions
and
0 deletions.
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
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 | ||
} |
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,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) | ||
} | ||
}) | ||
} | ||
} |
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 @@ | ||
// 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 | ||
} |