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)
| 53 | // and on parent directories, up to the maxDepth limit. |
| 54 | // It returns a result containing the file path and any warnings. |
| 55 | func 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. |
| 97 | func FindConfigFile(start string) (string, error) { |
no test coverage detected
searching dependent graphs…