loadAndMergeConfig loads configuration files in dirPath FIXME: Probably rename to loadRegistryConfigurationForPath
(dirPath string)
| 108 | // loadAndMergeConfig loads configuration files in dirPath |
| 109 | // FIXME: Probably rename to loadRegistryConfigurationForPath |
| 110 | func loadAndMergeConfig(dirPath string) (*registryConfiguration, error) { |
| 111 | mergedConfig := registryConfiguration{Docker: map[string]registryNamespace{}} |
| 112 | dockerDefaultMergedFrom := "" |
| 113 | nsMergedFrom := map[string]string{} |
| 114 | |
| 115 | dir, err := os.Open(dirPath) |
| 116 | if err != nil { |
| 117 | if os.IsNotExist(err) { |
| 118 | return &mergedConfig, nil |
| 119 | } |
| 120 | return nil, err |
| 121 | } |
| 122 | configNames, err := dir.Readdirnames(0) |
| 123 | if err != nil { |
| 124 | return nil, err |
| 125 | } |
| 126 | for _, configName := range configNames { |
| 127 | if !strings.HasSuffix(configName, ".yaml") { |
| 128 | continue |
| 129 | } |
| 130 | configPath := filepath.Join(dirPath, configName) |
| 131 | configBytes, err := os.ReadFile(configPath) |
| 132 | if err != nil { |
| 133 | if errors.Is(err, fs.ErrNotExist) { |
| 134 | // file must have been removed between the directory listing |
| 135 | // and the open call, ignore that as it is a expected race |
| 136 | continue |
| 137 | } |
| 138 | return nil, err |
| 139 | } |
| 140 | |
| 141 | var config registryConfiguration |
| 142 | err = yaml.Unmarshal(configBytes, &config) |
| 143 | if err != nil { |
| 144 | return nil, fmt.Errorf("parsing %s: %w", configPath, err) |
| 145 | } |
| 146 | |
| 147 | if config.DefaultDocker != nil { |
| 148 | if mergedConfig.DefaultDocker != nil { |
| 149 | return nil, fmt.Errorf(`Error parsing signature storage configuration: "default-docker" defined both in %q and %q`, |
| 150 | dockerDefaultMergedFrom, configPath) |
| 151 | } |
| 152 | mergedConfig.DefaultDocker = config.DefaultDocker |
| 153 | dockerDefaultMergedFrom = configPath |
| 154 | } |
| 155 | |
| 156 | for nsName, nsConfig := range config.Docker { // includes config.Docker == nil |
| 157 | if _, ok := mergedConfig.Docker[nsName]; ok { |
| 158 | return nil, fmt.Errorf(`Error parsing signature storage configuration: "docker" namespace %q defined both in %q and %q`, |
| 159 | nsName, nsMergedFrom[nsName], configPath) |
| 160 | } |
| 161 | mergedConfig.Docker[nsName] = nsConfig |
| 162 | nsMergedFrom[nsName] = configPath |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | return &mergedConfig, nil |
| 167 | } |
searching dependent graphs…