LoadDotChainloopConfig loads the chainloop config file from the current directory all the way up to the root directory or until a .git directory is found It supports both .yaml and .yml extensions
()
| 90 | // or until a .git directory is found |
| 91 | // It supports both .yaml and .yml extensions |
| 92 | func loadDotChainloopConfigWithParentTraversal() (*DotChainloopConfig, string, error) { |
| 93 | searchPaths := getConfigSearchPaths() |
| 94 | logger.Debug().Msgf("searching %s.[yaml|yml] file in %q", dotChainloopConfigFilename, searchPaths) |
| 95 | |
| 96 | for _, currentDir := range searchPaths { |
| 97 | for _, ext := range []string{".yaml", ".yml"} { |
| 98 | configPath := filepath.Join(currentDir, fmt.Sprintf("%s%s", dotChainloopConfigFilename, ext)) |
| 99 | // Check if the file exists |
| 100 | if _, err := os.Stat(configPath); !os.IsNotExist(err) { |
| 101 | // Load from the YAML file |
| 102 | file, err := os.Open(configPath) |
| 103 | if err != nil { |
| 104 | return nil, "", fmt.Errorf("opening attestation config file: %w", err) |
| 105 | } |
| 106 | defer file.Close() |
| 107 | |
| 108 | cfg := &DotChainloopConfig{} |
| 109 | decoder := yaml.NewDecoder(file) |
| 110 | if err := decoder.Decode(cfg); err != nil { |
| 111 | return nil, "", fmt.Errorf("decoding attestation config file: %w", err) |
| 112 | } |
| 113 | |
| 114 | return cfg, configPath, nil |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | return nil, "", errDotChainloopConfigNotFound |
| 120 | } |
| 121 | |
| 122 | // getConfigSearchPaths returns a slice of directory paths to search for the attestation configuration file. |
| 123 | // It starts from the current working directory and traverses up the directory tree up all the way to the root |
no test coverage detected