Get the module's content from a local file, memory, or a remote uri
( root string, t *cft.Template, templateFiles *embed.FS, baseUri string, uri string)
| 38 | |
| 39 | // Get the module's content from a local file, memory, or a remote uri |
| 40 | func getModuleContent( |
| 41 | root string, |
| 42 | t *cft.Template, |
| 43 | templateFiles *embed.FS, |
| 44 | baseUri string, |
| 45 | uri string) (*ModuleContent, error) { |
| 46 | |
| 47 | config.Debugf("getModuleContent root: %s, baseUri: %s, uri: %s", |
| 48 | root, baseUri, uri) |
| 49 | |
| 50 | cacheKey := fmt.Sprintf("%s/%s/%s", root, baseUri, uri) |
| 51 | |
| 52 | if cached, ok := contentCache[cacheKey]; ok { |
| 53 | config.Debugf("getModuleContent cache hit: %s", cacheKey) |
| 54 | return cached, nil |
| 55 | } |
| 56 | |
| 57 | var content []byte |
| 58 | var err error |
| 59 | var newRootDir string |
| 60 | |
| 61 | // Check to see if this is an alias like "$alias/foo.yaml" (new format) |
| 62 | isZip := false |
| 63 | if strings.HasPrefix(uri, "$") { |
| 64 | parts := strings.SplitN(uri, "/", 2) |
| 65 | if len(parts) == 2 { |
| 66 | alias := parts[0][1:] // Remove the $ prefix |
| 67 | path := parts[1] |
| 68 | |
| 69 | if t.Packages != nil { |
| 70 | if packageAlias, ok := t.Packages[alias]; ok { |
| 71 | |
| 72 | if strings.HasSuffix(packageAlias.Location, ".zip") { |
| 73 | isZip = true |
| 74 | zipLocation := resolveZipLocation(root, packageAlias.Location) |
| 75 | content, err = DownloadFromZip(zipLocation, packageAlias.Hash, path) |
| 76 | if err != nil { |
| 77 | return nil, err |
| 78 | } |
| 79 | } else { |
| 80 | // Replace the alias with the actual location |
| 81 | uri = packageAlias.Location + "/" + path |
| 82 | } |
| 83 | } else { |
| 84 | config.Debugf("Package alias not found: %s", alias) |
| 85 | } |
| 86 | } else { |
| 87 | config.Debugf("No packages defined in template") |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | // Look for a zip path where we already fixed the $alias |
| 93 | // getModuleContent: root=cft/pkg/tmpl/awscli-modules, baseUri=, uri=package.zip/zip-module.yaml |
| 94 | if strings.Contains(uri, ".zip/") { |
| 95 | isZip = true |
| 96 | |
| 97 | // Extract the zip location and path within the zip |
no test coverage detected