checkInvalidOptions checks invalid (renamed/deleted) configuration sections and options and returns a list of warnings. LEGACY [0.15]: Delete this function.
(config *ini.File)
| 445 | // |
| 446 | // LEGACY [0.15]: Delete this function. |
| 447 | func checkInvalidOptions(config *ini.File) (warnings []string) { |
| 448 | renamedSections := map[string]string{ |
| 449 | "mailer": "email", |
| 450 | "service": "auth", |
| 451 | } |
| 452 | for oldSection, newSection := range renamedSections { |
| 453 | if len(config.Section(oldSection).KeyStrings()) > 0 { |
| 454 | warnings = append(warnings, fmt.Sprintf("section [%s] is invalid, use [%s] instead", oldSection, newSection)) |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | type optionPath struct { |
| 459 | section string |
| 460 | option string |
| 461 | } |
| 462 | renamedOptionPaths := map[optionPath]optionPath{ |
| 463 | {"security", "REVERSE_PROXY_AUTHENTICATION_USER"}: {"auth", "REVERSE_PROXY_AUTHENTICATION_HEADER"}, |
| 464 | {"auth", "ACTIVE_CODE_LIVE_MINUTES"}: {"auth", "ACTIVATE_CODE_LIVES"}, |
| 465 | {"auth", "RESET_PASSWD_CODE_LIVE_MINUTES"}: {"auth", "RESET_PASSWORD_CODE_LIVES"}, |
| 466 | {"auth", "ENABLE_CAPTCHA"}: {"auth", "ENABLE_REGISTRATION_CAPTCHA"}, |
| 467 | {"auth", "ENABLE_NOTIFY_MAIL"}: {"user", "ENABLE_EMAIL_NOTIFICATION"}, |
| 468 | {"auth", "REGISTER_EMAIL_CONFIRM"}: {"auth", "REQUIRE_EMAIL_CONFIRMATION"}, |
| 469 | {"session", "GC_INTERVAL_TIME"}: {"session", "GC_INTERVAL"}, |
| 470 | {"session", "SESSION_LIFE_TIME"}: {"session", "MAX_LIFE_TIME"}, |
| 471 | {"server", "ROOT_URL"}: {"server", "EXTERNAL_URL"}, |
| 472 | {"server", "LANDING_PAGE"}: {"server", "LANDING_URL"}, |
| 473 | {"database", "DB_TYPE"}: {"database", "TYPE"}, |
| 474 | {"database", "PASSWD"}: {"database", "PASSWORD"}, |
| 475 | } |
| 476 | for oldPath, newPath := range renamedOptionPaths { |
| 477 | if config.Section(oldPath.section).HasKey(oldPath.option) { |
| 478 | warnings = append( |
| 479 | warnings, |
| 480 | fmt.Sprintf("option [%s] %s is invalid, use [%s] %s instead", |
| 481 | oldPath.section, oldPath.option, |
| 482 | newPath.section, newPath.option, |
| 483 | ), |
| 484 | ) |
| 485 | } |
| 486 | } |
| 487 | |
| 488 | // Check options that don't exist anymore. |
| 489 | defaultConfigData, err := conf.Files.ReadFile("app.ini") |
| 490 | if err != nil { |
| 491 | // Warning is best-effort, OK to skip on error. |
| 492 | return warnings |
| 493 | } |
| 494 | defaultConfig, err := ini.LoadSources( |
| 495 | ini.LoadOptions{IgnoreInlineComment: true}, |
| 496 | defaultConfigData, |
| 497 | ) |
| 498 | if err != nil { |
| 499 | // Warning is best-effort, OK to skip on error. |
| 500 | return warnings |
| 501 | } |
| 502 | for _, section := range config.Sections() { |
| 503 | // Skip sections already warned about. |
| 504 | if _, ok := renamedSections[section.Name()]; ok { |