Skip to content

Commit 58de5fe

Browse files
committed
rename function
1 parent 442f6f5 commit 58de5fe

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

config.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ func validateConfig(yamlData []byte) error {
209209

210210
// check config sections for unexpected keys
211211
allowedRepoPoolConfig := getAllowedKeys(mirror.RepoPoolConfig{})
212-
if key := validateConfigSection(raw, allowedRepoPoolConfig); key != "" {
212+
if key := findUnexpectedKey(raw, allowedRepoPoolConfig); key != "" {
213213
return fmt.Errorf("unexpected key: .%v", key)
214214
}
215215

@@ -220,14 +220,14 @@ func validateConfig(yamlData []byte) error {
220220
}
221221
allowedDefaults := getAllowedKeys(mirror.DefaultConfig{})
222222

223-
if key := validateConfigSection(defaultsMap, allowedDefaults); key != "" {
223+
if key := findUnexpectedKey(defaultsMap, allowedDefaults); key != "" {
224224
return fmt.Errorf("unexpected key: .defaults.%v", key)
225225
}
226226

227227
// check "auth" section in "defaults"
228228
if authMap, ok := defaultsMap["auth"].(map[string]interface{}); ok {
229229
allowedAuthKeys := getAllowedKeys(mirror.Auth{})
230-
if key := validateConfigSection(authMap, allowedAuthKeys); key != "" {
230+
if key := findUnexpectedKey(authMap, allowedAuthKeys); key != "" {
231231
return fmt.Errorf("unexpected key: .defaults.auth.%v", key)
232232
}
233233
}
@@ -240,7 +240,7 @@ func validateConfig(yamlData []byte) error {
240240
return fmt.Errorf("repositories config section is not valid")
241241
}
242242

243-
if key := validateConfigSection(repoMap, allowedRepoKeys); key != "" {
243+
if key := findUnexpectedKey(repoMap, allowedRepoKeys); key != "" {
244244
return fmt.Errorf("unexpected key: .repositories[%v].%v", repoMap["remote"], key)
245245
}
246246

@@ -252,7 +252,7 @@ func validateConfig(yamlData []byte) error {
252252
}
253253

254254
allowedWorktreeKeys := getAllowedKeys(mirror.WorktreeConfig{})
255-
if key := validateConfigSection(worktreeMap, allowedWorktreeKeys); key != "" {
255+
if key := findUnexpectedKey(worktreeMap, allowedWorktreeKeys); key != "" {
256256
return fmt.Errorf("unexpected key: .repositories[%v].worktrees[%v].%v", repoMap["remote"], worktreeMap["link"], key)
257257
}
258258
}
@@ -261,16 +261,6 @@ func validateConfig(yamlData []byte) error {
261261
return nil
262262
}
263263

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-
274264
// getAllowedKeys retrieves a list of allowed keys from the specified struct
275265
func getAllowedKeys(config interface{}) []string {
276266
var allowedKeys []string
@@ -287,6 +277,16 @@ func getAllowedKeys(config interface{}) []string {
287277
return allowedKeys
288278
}
289279

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+
290290
// diffRepositories will do the diff between current state and new config and
291291
// return new repositories config and list of remote url which are not found in config
292292
func diffRepositories(repoPool *mirror.RepoPool, newConfig *mirror.RepoPoolConfig) (

0 commit comments

Comments
 (0)