MCPcopy Index your code
hub / github.com/getsops/sops / LookupConfigFile

Function LookupConfigFile

config/config.go:55–94  ·  view source on GitHub ↗

LookupConfigFile looks for a sops config file in the current working directory and on parent directories, up to the maxDepth limit. It returns a result containing the file path and any warnings.

(start string)

Source from the content-addressed store, hash-verified

53// and on parent directories, up to the maxDepth limit.
54// It returns a result containing the file path and any warnings.
55func LookupConfigFile(start string) (ConfigFileResult, error) {
56 filepath := path.Dir(start)
57 var foundAlternatePath string
58
59 for i := 0; i < maxDepth; i++ {
60 configPath := path.Join(filepath, configFileName)
61 _, err := fs.Stat(configPath)
62 if err == nil {
63 result := ConfigFileResult{Path: configPath}
64
65 if foundAlternatePath != "" {
66 result.Warning = fmt.Sprintf(
67 "ignoring %q when searching for config file; the config file must be called %q; using %q instead",
68 foundAlternatePath, configFileName, configPath)
69 }
70 return result, nil
71 }
72
73 // Check for alternate filename if we haven't found one yet
74 if foundAlternatePath == "" {
75 alternatePath := path.Join(filepath, alternateConfigName)
76 _, altErr := fs.Stat(alternatePath)
77 if altErr == nil {
78 foundAlternatePath = alternatePath
79 }
80 }
81
82 filepath = path.Join(filepath, "..")
83 }
84
85 // No config file found
86 result := ConfigFileResult{}
87 if foundAlternatePath != "" {
88 result.Warning = fmt.Sprintf(
89 "ignoring %q when searching for config file; the config file must be called %q",
90 foundAlternatePath, configFileName)
91 }
92
93 return result, fmt.Errorf("config file not found")
94}
95
96// 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.
97func FindConfigFile(start string) (string, error) {

Callers 2

findConfigFileFunction · 0.92
FindConfigFileFunction · 0.85

Calls 1

StatMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…