Documentation
¶
Overview ¶
Package imports provides functionality for processing stack imports, including support for remote imports from URLs via go-getter.
Index ¶
- func DownloadRemoteImport(atmosConfig *schema.AtmosConfiguration, uri string) (string, error)
- func HasSchemeSeparator(uri string) bool
- func IsGCSURI(uri string) bool
- func IsGitURI(uri string) bool
- func IsHTTPURI(uri string) bool
- func IsLocalPath(uri string) bool
- func IsRemote(uri string) bool
- func IsS3URI(uri string) bool
- func IsTemplateFile(filePath string) bool
- func IsTemplatedPath(importPath string) bool
- func ProcessImportPath(atmosConfig *schema.AtmosConfiguration, basePath, importPath string) (string, error)
- func ResolveImportPaths(atmosConfig *schema.AtmosConfiguration, basePath string, importPaths []string) ([]string, error)
- func ResolveLocal(importPath, importingFile, stacksBasePath string) ([]string, error)
- type RemoteImportMatch
- type RemoteImporter
- type RemoteImporterOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DownloadRemoteImport ¶
func DownloadRemoteImport(atmosConfig *schema.AtmosConfiguration, uri string) (string, error)
DownloadRemoteImport is a convenience function that uses the global importer.
func HasSchemeSeparator ¶
HasSchemeSeparator checks if the URI contains a scheme separator. Examples:
- true: "https://github.com", "git::https://...", "s3::https://...".
- false: "github.com/repo", "./local/path", "components/terraform".
func IsGitURI ¶
IsGitURI checks if the URI appears to be a Git repository URL. Detection rules: 1. Explicit git:: prefix. 2. SCP-style URLs (git@github.com:owner/repo.git). 3. Known Git hosting platforms (github.com, gitlab.com, bitbucket.org) in host. 4. .git extension in path (not in host). 5. Azure DevOps _git/ pattern in path.
func IsLocalPath ¶
IsLocalPath checks if the URI is a local file system path. Examples:
- Local: "/absolute/path", "./relative/path", "../parent/path", "components/terraform".
- Remote: "github.com/owner/repo", "https://example.com", "git.company.com/repo".
func IsRemote ¶
IsRemote returns true if the URI is a remote URL that should be downloaded. This is the inverse of IsLocalPath.
func IsS3URI ¶
IsS3URI checks if the URI is an S3 URI. Go-getter supports both explicit s3:: prefix and auto-detected .amazonaws.com URLs.
func IsTemplateFile ¶
IsTemplateFile reports whether a resolved import file is a Go template file (`.yaml.tmpl` or `.yml.tmpl`) that must be rendered before it can be parsed as YAML.
func IsTemplatedPath ¶
IsTemplatedPath reports whether an import path contains a Go template expression. Templated import paths can only be resolved at stack-processing time (they depend on the `settings`/`vars`/`env` sections of earlier imports), so static resolvers skip them.
func ProcessImportPath ¶
func ProcessImportPath(atmosConfig *schema.AtmosConfiguration, basePath, importPath string) (string, error)
ProcessImportPath resolves an import path (local or remote) to a local file path. For local paths, it joins with basePath. For remote URLs, it downloads and returns the temp file path.
func ResolveImportPaths ¶
func ResolveImportPaths(atmosConfig *schema.AtmosConfiguration, basePath string, importPaths []string) ([]string, error)
ResolveImportPaths resolves multiple import paths, returning local file paths. This is a convenience function for batch processing.
func ResolveLocal ¶
ResolveLocal resolves a single local stack import to the files on disk that the stack processor would load for it. It has no side effects, never reads file contents, and never renders templates.
Semantics mirror the runtime stack processor (internal/exec ProcessImportSection and processYAMLConfigFileWithContextInternal):
- `./` and `../` import paths are relative to the importing file's directory; every other path is relative to stacksBasePath.
- An import with no extension tries `.yaml`, `.yml`, `.yaml.tmpl`, `.yml.tmpl` in that order and falls back to `.yaml`.
- An import ending in `.yaml` or `.yml` is upgraded to the `.tmpl` sibling when that file exists.
- Glob patterns (including doublestar `**`) are expanded.
Remote imports (see IsRemote) and templated paths (see IsTemplatedPath) are not handled here; callers must filter them out first.
It returns errUtils.ErrStackImportNotFound (wrapped) when nothing matches, and errUtils.ErrInvalidImport (wrapped) when the path is empty or a non-relative path is given without a stacksBasePath.
Types ¶
type RemoteImportMatch ¶
RemoteImportMatch is a resolved remote stack import ready for local processing.
func ResolveRemoteImport ¶
func ResolveRemoteImport(atmosConfig *schema.AtmosConfiguration, uri string) ([]RemoteImportMatch, error)
ResolveRemoteImport is a convenience function that uses the global importer.
func ResolveRemoteImportNested ¶
func ResolveRemoteImportNested(atmosConfig *schema.AtmosConfiguration, uri, nestedImports, ttl string) ([]RemoteImportMatch, error)
ResolveRemoteImportNested is a convenience function that uses the global importer. The ttl controls cross-run reuse of the cloned source repo for git subdir imports (see ensureSourceDir); an empty ttl refreshes the clone once per invocation.
type RemoteImporter ¶
type RemoteImporter struct {
// contains filtered or unexported fields
}
RemoteImporter handles downloading stack imports from remote URLs.
func NewRemoteImporter ¶
func NewRemoteImporter(atmosConfig *schema.AtmosConfiguration, opts ...RemoteImporterOption) (*RemoteImporter, error)
NewRemoteImporter creates a new RemoteImporter.
func (*RemoteImporter) ClearCache ¶
func (r *RemoteImporter) ClearCache() error
ClearCache removes all cached imports.
func (*RemoteImporter) Download ¶
func (r *RemoteImporter) Download(uri string) (result string, resultErr error)
Download fetches a remote import and returns the local path. Downloads are cached by URL hash to avoid redundant downloads. Uses file locking and atomic writes for safe concurrent access.
Honors the same atmosConfig.Imports.TTL default Resolve does. An empty ttl preserves this cache's historical behavior: once downloaded, a URL is reused indefinitely within this cache directory (no expiry) until the cache is cleared. A non-empty ttl instead expires the cached content after ttl, matching the freshness semantics ensureSourceDir uses for git-subdir imports, so the same setting governs both caching mechanisms.
func (*RemoteImporter) Resolve ¶
func (r *RemoteImporter) Resolve(uri string) ([]RemoteImportMatch, error)
Resolve fetches a remote import and returns all local stack files it resolves to.
Honors the global atmosConfig.Imports.TTL default (the same setting stack-manifest imports fall back to via ResolveRemoteImportNested) for cross-run reuse of the cloned source repo; an unset TTL refreshes the clone once per invocation, as before.
func (*RemoteImporter) ResolveNested ¶
func (r *RemoteImporter) ResolveNested(uri, nestedImports string) ([]RemoteImportMatch, error)
ResolveNested fetches a remote import and returns all local stack files it resolves to, preserving remote source context when nested imports should resolve remotely.
The cached source clone is refreshed on every invocation (no cross-run reuse); use ResolveRemoteImportNested with a TTL when cross-run cache reuse is desired.
type RemoteImporterOption ¶
type RemoteImporterOption func(*RemoteImporter)
RemoteImporterOption is a functional option for configuring RemoteImporter.
func WithCache ¶
func WithCache(c *cache.FileCache) RemoteImporterOption
WithCache sets a custom FileCache (useful for testing).
func WithDownloader ¶
func WithDownloader(d downloader.FileDownloader) RemoteImporterOption
WithDownloader sets a custom downloader (useful for testing).