From b70288498642760fe09314c7f1f900aa10030ae5 Mon Sep 17 00:00:00 2001 From: haitham911 Date: Fri, 13 Dec 2024 13:39:19 +0200 Subject: [PATCH] fix: improve atmos.d path validation and add support for .atmos.d directory imports --- pkg/config/config.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 74e8515ed..857cf28a5 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -252,15 +252,24 @@ func InitCliConfig(configAndStacksInfo schema.ConfigAndStacksInfo, processStacks atmosDPath := filepath.Join(basePath, "atmos.d") // Ensure the joined path doesn't escape the intended directory if !strings.HasPrefix(atmosDPath, basePath) { - u.LogWarning(cliConfig, fmt.Sprintf("Warning: invalid atmos.d path: attempted directory traversal")) + u.LogWarning(cliConfig, "invalid atmos.d path: attempted directory traversal") } - _, err = os.Stat(atmosDPath) if err == nil { - cliConfig.Import = []string{"atmos.d/**/*.yaml", "atmos.d/**/*.yml", ".atmos.d/**/*.yaml", ".atmos.d/**/*.yml"} + cliConfig.Import = []string{"atmos.d/**/*.yaml", "atmos.d/**/*.yml"} } else if !os.IsNotExist(err) { return cliConfig, err // Handle unexpected errors } + // Check for `.atmos.d` directory if `.atmos.d` directory is not found + atmosDPath = filepath.Join(atmosDPath, ".atmos.d") + _, err = os.Stat(atmosDPath) + if err == nil { + cliImport := []string{".atmos.d/**/*.yaml", ".atmos.d/**/*.yml"} + cliConfig.Import = append(cliConfig.Import, cliImport...) + } else if !os.IsNotExist(err) { + return cliConfig, err // Handle unexpected errors + } + } // Process imports if any if len(cliConfig.Import) > 0 {