Skip to content

Commit f958052

Browse files
committed
Remove support for .yml config extension and just log warning instead
1 parent 4619e54 commit f958052

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

config/config.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,32 @@ var fs fileSystem = osFS{stat: os.Stat}
3939
const (
4040
maxDepth = 100
4141
configFileName = ".sops.yaml"
42-
configFileNameAlternative = ".sops.yml"
4342
)
4443

4544
// 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.
4645
func FindConfigFile(start string) (string, error) {
4746
filepath := path.Dir(start)
4847
for i := 0; i < maxDepth; i++ {
49-
for _, configFileName := range []string{configFileName, configFileNameAlternative} {
50-
_, err := fs.Stat(path.Join(filepath, configFileName))
51-
if err != nil {
52-
filepath = path.Join(filepath, "..")
53-
} else {
54-
return path.Join(filepath, configFileName), nil
55-
}
48+
_, err := fs.Stat(path.Join(filepath, configFileName))
49+
if err != nil {
50+
// Check if user mispelled '.sops.yaml'
51+
warnWrongConfigFileExtension(filepath)
52+
filepath = path.Join(filepath, "..")
53+
} else {
54+
return path.Join(filepath, configFileName), nil
5655
}
5756
}
5857
return "", fmt.Errorf("Config file not found")
5958
}
6059

60+
func warnWrongConfigFileExtension(filepath string) {
61+
_, err :=
62+
fs.Stat(path.Join(filepath, ".sops.yml"))
63+
if err == nil {
64+
log.Printf("warning: Found unsupported '.sops.yml' config file. Rename it to '.sops.yaml' or use '--config .sops.yml' flag")
65+
}
66+
}
67+
6168
type DotenvStoreConfig struct{}
6269

6370
type INIStoreConfig struct{}

0 commit comments

Comments
 (0)