@@ -209,7 +209,7 @@ func validateConfig(yamlData []byte) error {
209
209
210
210
// check config sections for unexpected keys
211
211
allowedRepoPoolConfig := getAllowedKeys (mirror.RepoPoolConfig {})
212
- if key := validateConfigSection (raw , allowedRepoPoolConfig ); key != "" {
212
+ if key := findUnexpectedKey (raw , allowedRepoPoolConfig ); key != "" {
213
213
return fmt .Errorf ("unexpected key: .%v" , key )
214
214
}
215
215
@@ -220,14 +220,14 @@ func validateConfig(yamlData []byte) error {
220
220
}
221
221
allowedDefaults := getAllowedKeys (mirror.DefaultConfig {})
222
222
223
- if key := validateConfigSection (defaultsMap , allowedDefaults ); key != "" {
223
+ if key := findUnexpectedKey (defaultsMap , allowedDefaults ); key != "" {
224
224
return fmt .Errorf ("unexpected key: .defaults.%v" , key )
225
225
}
226
226
227
227
// check "auth" section in "defaults"
228
228
if authMap , ok := defaultsMap ["auth" ].(map [string ]interface {}); ok {
229
229
allowedAuthKeys := getAllowedKeys (mirror.Auth {})
230
- if key := validateConfigSection (authMap , allowedAuthKeys ); key != "" {
230
+ if key := findUnexpectedKey (authMap , allowedAuthKeys ); key != "" {
231
231
return fmt .Errorf ("unexpected key: .defaults.auth.%v" , key )
232
232
}
233
233
}
@@ -240,7 +240,7 @@ func validateConfig(yamlData []byte) error {
240
240
return fmt .Errorf ("repositories config section is not valid" )
241
241
}
242
242
243
- if key := validateConfigSection (repoMap , allowedRepoKeys ); key != "" {
243
+ if key := findUnexpectedKey (repoMap , allowedRepoKeys ); key != "" {
244
244
return fmt .Errorf ("unexpected key: .repositories[%v].%v" , repoMap ["remote" ], key )
245
245
}
246
246
@@ -252,7 +252,7 @@ func validateConfig(yamlData []byte) error {
252
252
}
253
253
254
254
allowedWorktreeKeys := getAllowedKeys (mirror.WorktreeConfig {})
255
- if key := validateConfigSection (worktreeMap , allowedWorktreeKeys ); key != "" {
255
+ if key := findUnexpectedKey (worktreeMap , allowedWorktreeKeys ); key != "" {
256
256
return fmt .Errorf ("unexpected key: .repositories[%v].worktrees[%v].%v" , repoMap ["remote" ], worktreeMap ["link" ], key )
257
257
}
258
258
}
@@ -261,16 +261,6 @@ func validateConfig(yamlData []byte) error {
261
261
return nil
262
262
}
263
263
264
- func validateConfigSection (raw interface {}, allowedKeys []string ) string {
265
- for key := range raw .(map [string ]interface {}) {
266
- if ! slices .Contains (allowedKeys , key ) {
267
- return key
268
- }
269
- }
270
-
271
- return ""
272
- }
273
-
274
264
// getAllowedKeys retrieves a list of allowed keys from the specified struct
275
265
func getAllowedKeys (config interface {}) []string {
276
266
var allowedKeys []string
@@ -287,6 +277,16 @@ func getAllowedKeys(config interface{}) []string {
287
277
return allowedKeys
288
278
}
289
279
280
+ func findUnexpectedKey (raw interface {}, allowedKeys []string ) string {
281
+ for key := range raw .(map [string ]interface {}) {
282
+ if ! slices .Contains (allowedKeys , key ) {
283
+ return key
284
+ }
285
+ }
286
+
287
+ return ""
288
+ }
289
+
290
290
// diffRepositories will do the diff between current state and new config and
291
291
// return new repositories config and list of remote url which are not found in config
292
292
func diffRepositories (repoPool * mirror.RepoPool , newConfig * mirror.RepoPoolConfig ) (
0 commit comments