From 4619e5492b432461657bb915252d0a0f3dc5d976 Mon Sep 17 00:00:00 2001 From: Onni Hakala Date: Thu, 13 Mar 2025 17:53:19 +0100 Subject: [PATCH 1/2] Add support for .yml file extension in config file Signed-off-by: Onni Hakala --- config/config.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/config/config.go b/config/config.go index 8d3dc4dd1..933d01e40 100644 --- a/config/config.go +++ b/config/config.go @@ -39,17 +39,20 @@ var fs fileSystem = osFS{stat: os.Stat} const ( maxDepth = 100 configFileName = ".sops.yaml" + configFileNameAlternative = ".sops.yml" ) // FindConfigFile looks for a sops config file in the current working directory and on parent directories, up to the limit defined by the maxDepth constant. func FindConfigFile(start string) (string, error) { filepath := path.Dir(start) for i := 0; i < maxDepth; i++ { - _, err := fs.Stat(path.Join(filepath, configFileName)) - if err != nil { - filepath = path.Join(filepath, "..") - } else { - return path.Join(filepath, configFileName), nil + for _, configFileName := range []string{configFileName, configFileNameAlternative} { + _, err := fs.Stat(path.Join(filepath, configFileName)) + if err != nil { + filepath = path.Join(filepath, "..") + } else { + return path.Join(filepath, configFileName), nil + } } } return "", fmt.Errorf("Config file not found") From f0ea3ac2a33c5655fa40b130ebef3acc6bd7efeb Mon Sep 17 00:00:00 2001 From: Onni Hakala Date: Tue, 18 Mar 2025 21:58:02 +0100 Subject: [PATCH 2/2] Remove support for .yml config extension and just log warning instead Signed-off-by: Onni Hakala --- config/config.go | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/config/config.go b/config/config.go index 933d01e40..c29b86ab8 100644 --- a/config/config.go +++ b/config/config.go @@ -39,25 +39,32 @@ var fs fileSystem = osFS{stat: os.Stat} const ( maxDepth = 100 configFileName = ".sops.yaml" - configFileNameAlternative = ".sops.yml" ) // FindConfigFile looks for a sops config file in the current working directory and on parent directories, up to the limit defined by the maxDepth constant. func FindConfigFile(start string) (string, error) { filepath := path.Dir(start) for i := 0; i < maxDepth; i++ { - for _, configFileName := range []string{configFileName, configFileNameAlternative} { - _, err := fs.Stat(path.Join(filepath, configFileName)) - if err != nil { - filepath = path.Join(filepath, "..") - } else { - return path.Join(filepath, configFileName), nil - } + _, err := fs.Stat(path.Join(filepath, configFileName)) + if err != nil { + // Check if user mispelled '.sops.yaml' + warnWrongConfigFileExtension(filepath) + filepath = path.Join(filepath, "..") + } else { + return path.Join(filepath, configFileName), nil } } return "", fmt.Errorf("Config file not found") } +func warnWrongConfigFileExtension(filepath string) { + _, err := + fs.Stat(path.Join(filepath, ".sops.yml")) + if err == nil { + log.Printf("warning: Found unsupported '.sops.yml' config file. Rename it to '.sops.yaml' or use '--config .sops.yml' flag") + } +} + type DotenvStoreConfig struct{} type INIStoreConfig struct{}