Skip to content

Commit

Permalink
use log debug
Browse files Browse the repository at this point in the history
  • Loading branch information
haitham911 committed Feb 6, 2025
1 parent 2088f36 commit 4e12998
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 109 deletions.
14 changes: 7 additions & 7 deletions pkg/config/base_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ func (cl *ConfigLoader) BasePathComputing(configAndStacksInfo schema.ConfigAndSt
if err != nil {
return "", err
}
cl.debugLogging(fmt.Sprintf("base path from %s: %s", "infra", absPath))
u.LogDebug(fmt.Sprintf("base path from %s: %s", "infra", absPath))
return absPath, nil
}
// Set base_path to absolute path of ./
absPath, err := filepath.Abs("./")
if err != nil {
return "", err
}
cl.debugLogging(fmt.Sprintf("base path from %s: %s", "PWD", pwd))
u.LogDebug(fmt.Sprintf("base path from %s: %s", "PWD", pwd))
return absPath, nil
}

Expand All @@ -77,7 +77,7 @@ func (cl *ConfigLoader) resolveAndValidatePath(path string, source string) (stri
return "", fmt.Errorf("base path from %s is not a directory: %w", source, err)
}

cl.debugLogging(fmt.Sprintf("base path from %s: %s", source, path))
u.LogDebug(fmt.Sprintf("base path from %s: %s", source, path))
return absPath, nil
}

Expand All @@ -86,12 +86,12 @@ func (cl *ConfigLoader) infraBasePath(cwd string) (string, bool) {
// if found Set base_path to absolute path containing directory
filePath, found := cl.SearchConfigFilePath(filepath.Join(cwd, "atmos"))
if found {
cl.debugLogging(fmt.Sprintf("base path from infra %s: %s", "atmos", filePath))
u.LogDebug(fmt.Sprintf("base path from infra %s: %s", "atmos", filePath))
return filepath.Dir(filePath), found
}
filePath, found = cl.SearchConfigFilePath(filepath.Join(cwd, ".atmos"))
if found {
cl.debugLogging(fmt.Sprintf("base path from infra %s: %s", ".atmos", filePath))
u.LogDebug(fmt.Sprintf("base path from infra %s: %s", ".atmos", filePath))
return filepath.Dir(filePath), found
}
filePaths, _ := u.GetGlobMatches(filepath.ToSlash(filepath.Join(cwd, "atmos.d/**/*.yaml")))
Expand All @@ -100,14 +100,14 @@ func (cl *ConfigLoader) infraBasePath(cwd string) (string, bool) {
}
if len(filePaths) > 0 {
filePaths = cl.sortFilesByDepth(filePaths)
cl.debugLogging(fmt.Sprintf("base path from infra %s: %s", "atmos.d", filePaths[0]))
u.LogDebug(fmt.Sprintf("base path from infra %s: %s", "atmos.d", filePaths[0]))
return filepath.Dir(filePaths[0]), true
}
gitTopLevel, err := u.GetGitRoot()
if err == nil {
dirAbs, found := cl.SearchConfigFilePath(filepath.Join(gitTopLevel, "atmos"))
if found {
cl.debugLogging(fmt.Sprintf("base path from infra %s: %s", "git root", filePath))
u.LogDebug(fmt.Sprintf("base path from infra %s: %s", "git root", filePath))
return dirAbs, found
}
}
Expand Down
11 changes: 6 additions & 5 deletions pkg/config/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

"github.com/cloudposse/atmos/pkg/schema"
u "github.com/cloudposse/atmos/pkg/utils"
"github.com/hashicorp/go-getter"
"github.com/spf13/viper"
)
Expand Down Expand Up @@ -51,15 +52,15 @@ func (cl *ConfigLoader) processImports(importPaths []string, tempDir string, cur
// Handle remote imports
paths, err := cl.processRemoteImport(importPath, tempDir, currentDepth, maxDepth)
if err != nil {
cl.debugLogging(fmt.Sprintf("failed to process remote import '%s': %v", importPath, err))
u.LogDebug(fmt.Sprintf("failed to process remote import '%s': %v", importPath, err))
continue
}
resolvedPaths = append(resolvedPaths, paths...)
} else {
// Handle local imports
paths, err := cl.processLocalImport(importPath, tempDir, currentDepth, maxDepth)
if err != nil {
cl.debugLogging(fmt.Sprintf("failed to process local import '%s': %v", importPath, err))
u.LogDebug(fmt.Sprintf("failed to process local import '%s': %v", importPath, err))
continue
}
resolvedPaths = append(resolvedPaths, paths...)
Expand Down Expand Up @@ -133,21 +134,21 @@ func (cl *ConfigLoader) processLocalImport(importPath, tempDir string, currentDe
v.SetConfigType("yaml")
found, err := cl.loadConfigFileViber(cl.atmosConfig, path, v)
if err != nil || !found {
cl.debugLogging(fmt.Sprintf("failed to load local config '%s': %v", path, err))
u.LogDebug(fmt.Sprintf("failed to load local config '%s': %v", path, err))
continue
}

var importedConfig schema.AtmosConfiguration
if err := v.Unmarshal(&importedConfig); err != nil {
cl.debugLogging(fmt.Sprintf("failed to unmarshal local config '%s': %v", path, err))
u.LogDebug(fmt.Sprintf("failed to unmarshal local config '%s': %v", path, err))
continue
}

// Recursively process imports from the local file
if importedConfig.Import != nil {
nestedPaths, err := cl.processImports(importedConfig.Import, tempDir, currentDepth+1, maxDepth)
if err != nil {
cl.debugLogging(fmt.Sprintf("failed to process nested imports from '%s': %v", path, err))
u.LogDebug(fmt.Sprintf("failed to process nested imports from '%s': %v", path, err))
continue
}
resolvedPaths = append(resolvedPaths, nestedPaths...)
Expand Down
Loading

0 comments on commit 4e12998

Please sign in to comment.