MCPcopy Create free account
hub / github.com/aws-cloudformation/rain / processModulesSection

Function processModulesSection

cft/pkg/module.go:79–163  ·  view source on GitHub ↗

Process the Modules section of a template or module. Modifies t in place.

(t *cft.Template, n *yaml.Node,
	rootDir string, fs *embed.FS, parentModule *Module)

Source from the content-addressed store, hash-verified

77// Process the Modules section of a template or module.
78// Modifies t in place.
79func processModulesSection(t *cft.Template, n *yaml.Node,
80 rootDir string, fs *embed.FS, parentModule *Module) error {
81
82 // AWS CLI package Modules compatibility.
83 // This is basically the same as !Rain::Module but the modules are
84 // defined in a new Modules Section.
85 _, moduleSection, _ := s11n.GetMapValue(n, "Modules")
86 if moduleSection == nil {
87 return nil
88 }
89 HasModules = true
90
91 if moduleSection.Kind != yaml.MappingNode {
92 return errors.New("the Modules section is not a mapping node")
93 }
94
95 originalContent := moduleSection.Content
96
97 // Duplicate module content that has a ForEach attribute
98 content, err := processMaps(originalContent, t, parentModule)
99 if err != nil {
100 return err
101 }
102
103 // Replace the original Modules content
104 moduleSection.Content = content
105
106 for i := 0; i < len(content); i += 2 {
107 name := content[i].Value
108 moduleConfig, err := t.ParseModuleConfig(name, content[i+1])
109 if err != nil {
110 return err
111 }
112 moduleConfig.ParentRootDir = rootDir
113
114 baseUri := ""
115 uri := moduleConfig.Source
116
117 moduleContent, err := getModuleContent(rootDir, t, fs, baseUri, uri)
118 if err != nil {
119 return err
120 }
121
122 parsed, err := parseModule(moduleContent.Content,
123 moduleContent.NewRootDir, fs)
124 if err != nil {
125 return err
126 }
127
128 // Transform the parsed module content
129 outputNode := node.MakeMapping()
130
131 err = processModule(
132 parsed,
133 outputNode,
134 t,
135 moduleConfig,
136 parentModule)

Callers 1

processAddedSectionsFunction · 0.85

Calls 12

GetMapValueFunction · 0.92
MakeMappingFunction · 0.92
AddMapFunction · 0.92
DebugfFunction · 0.92
processMapsFunction · 0.85
getModuleContentFunction · 0.85
parseModuleFunction · 0.85
processModuleFunction · 0.85
ProcessOutputArraysFunction · 0.85
ParseModuleConfigMethod · 0.80
GetSectionMethod · 0.80
RemoveSectionMethod · 0.80

Tested by

no test coverage detected