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

Function includeS3Object

cft/pkg/directives.go:206–257  ·  view source on GitHub ↗
(ctx *directiveContext)

Source from the content-addressed store, hash-verified

204}
205
206func includeS3Object(ctx *directiveContext) (bool, error) {
207
208 n := ctx.n
209 parent := ctx.parent
210 if n.Kind != yaml.MappingNode || len(n.Content) != 2 {
211 return false, errors.New("expected a map")
212 }
213
214 // Check to see if any of the properties is a Ref.
215 // The only valid use case is if the !Rain::S3 directive is inside a module,
216 // and the Ref points to one of the properties set in the parent template
217 for i := 0; i < len(n.Content[1].Content); i += 2 {
218 s3opt := n.Content[1].Content[i+1]
219 name := n.Content[1].Content[i].Value
220 if s3opt.Kind == yaml.MappingNode {
221 if s3opt.Content[0].Value == "Ref" {
222 if parent.Parent != nil {
223 moduleParentMap := parent.Parent.Value
224 _, moduleParentProps, _ := s11n.GetMapValue(moduleParentMap, "Properties")
225 if moduleParentProps != nil {
226 _, parentProp, _ := s11n.GetMapValue(moduleParentProps, s3opt.Content[1].Value)
227 if parentProp != nil {
228 // Replace the Ref with the value
229 node.SetMapValue(n.Content[1], name, node.Clone(parentProp))
230 } else {
231 config.Debugf("expected Properties to have Path")
232 }
233 } else {
234 config.Debugf("expected parent resource to have Properties")
235 config.Debugf("moduleParentMap: %s", node.ToSJson(moduleParentMap))
236 }
237 }
238 }
239 }
240 }
241
242 // Parse the options
243 var options s3Options
244 err := n.Content[1].Decode(&options)
245 if err != nil {
246 return false, err
247 }
248
249 newNode, err := handleS3(ctx.rootDir, options)
250 if err != nil {
251 return false, err
252 }
253
254 *n = *newNode
255
256 return true, nil
257}
258
259func includeS3Http(ctx *directiveContext) (bool, error) {
260 path, err := expectString(ctx.n)

Callers 1

includeS3Function · 0.85

Calls 6

GetMapValueFunction · 0.92
SetMapValueFunction · 0.92
CloneFunction · 0.92
DebugfFunction · 0.92
ToSJsonFunction · 0.92
handleS3Function · 0.85

Tested by

no test coverage detected