diff --git a/modules/setting/config_provider.go b/modules/setting/config_provider.go index 3138f8a63eeda..4a6132a2eb681 100644 --- a/modules/setting/config_provider.go +++ b/modules/setting/config_provider.go @@ -324,9 +324,20 @@ func LogStartupProblem(skip int, level log.Level, format string, args ...any) { StartupProblems = append(StartupProblems, msg) } +// deprecatedSetting creates a warning about a setting that will be removed in the near future func deprecatedSetting(rootCfg ConfigProvider, oldSection, oldKey, newSection, newKey, version string) { if rootCfg.Section(oldSection).HasKey(oldKey) { - LogStartupProblem(1, log.ERROR, "Deprecation: config option `[%s].%s` presents, please use `[%s].%s` instead because this fallback will be/has been removed in %s", oldSection, oldKey, newSection, newKey, version) + LogStartupProblem(1, log.ERROR, "Deprecation: config option `[%s].%s` is present, please use `[%s].%s` instead. This fallback will be removed in %s", oldSection, oldKey, newSection, newKey, version) + } +} + +// make linter happy when there is no deprecated setting at the moment +var _ = deprecatedSetting + +// removedSettingWarning is a warning about a setting that has already been removed, giving the user a last chance to fix their app.ini +func removedSettingWarning(rootCfg ConfigProvider, oldSection, oldKey, newSection, newKey, version string) { + if rootCfg.Section(oldSection).HasKey(oldKey) { + LogStartupProblem(1, log.ERROR, "Removed: config option `[%s].%s` presents, please use `[%s].%s` instead because this setting has been removed in %s", oldSection, oldKey, newSection, newKey, version) } } diff --git a/modules/setting/git.go b/modules/setting/git.go index 48a4e7f30deb5..9c4739333a765 100644 --- a/modules/setting/git.go +++ b/modules/setting/git.go @@ -97,15 +97,9 @@ func loadGitFrom(rootCfg ConfigProvider) { GitConfig.SetOption("core.logAllRefUpdates", "true") GitConfig.SetOption("gc.reflogExpire", "90") - secGitReflog := rootCfg.Section("git.reflog") - if secGitReflog.HasKey("ENABLED") { - deprecatedSetting(rootCfg, "git.reflog", "ENABLED", "git.config", "core.logAllRefUpdates", "1.21") - GitConfig.SetOption("core.logAllRefUpdates", secGitReflog.Key("ENABLED").In("true", []string{"true", "false"})) - } - if secGitReflog.HasKey("EXPIRATION") { - deprecatedSetting(rootCfg, "git.reflog", "EXPIRATION", "git.config", "core.reflogExpire", "1.21") - GitConfig.SetOption("gc.reflogExpire", secGitReflog.Key("EXPIRATION").String()) - } + // keep warning here but not read the option + removedSettingWarning(rootCfg, "git.reflog", "ENABLED", "git.config", "core.logAllRefUpdates", "1.21") + removedSettingWarning(rootCfg, "git.reflog", "EXPIRATION", "git.config", "core.reflogExpire", "1.21") for _, key := range secGitConfig.Keys() { GitConfig.SetOption(key.Name(), key.String()) diff --git a/modules/setting/lfs.go b/modules/setting/lfs.go index 7f2d0ae159061..7641c9fc3825a 100644 --- a/modules/setting/lfs.go +++ b/modules/setting/lfs.go @@ -40,17 +40,9 @@ func loadLFSFrom(rootCfg ConfigProvider) error { lfsSec, _ := rootCfg.GetSection("lfs") - // Specifically default PATH to LFS_CONTENT_PATH // DEPRECATED should not be removed because users maybe upgrade from lower version to the latest version // if these are removed, the warning will not be shown - deprecatedSetting(rootCfg, "server", "LFS_CONTENT_PATH", "lfs", "PATH", "v1.19.0") - - if val := sec.Key("LFS_CONTENT_PATH").String(); val != "" { - if lfsSec == nil { - lfsSec = rootCfg.Section("lfs") - } - lfsSec.Key("PATH").MustString(val) - } + removedSettingWarning(rootCfg, "server", "LFS_CONTENT_PATH", "lfs", "PATH", "v1.19.0") var err error LFS.Storage, err = getStorage(rootCfg, "lfs", "", lfsSec) diff --git a/modules/setting/log.go b/modules/setting/log.go index 50c57799945e5..713cf11f7791d 100644 --- a/modules/setting/log.go +++ b/modules/setting/log.go @@ -60,38 +60,22 @@ func prepareLoggerConfig(rootCfg ConfigProvider) { sec.Key("logger.default.MODE").MustString(",") } - deprecatedSetting(rootCfg, "log", "ACCESS", "log", "logger.access.MODE", "1.21") - deprecatedSetting(rootCfg, "log", "ENABLE_ACCESS_LOG", "log", "logger.access.MODE", "1.21") - if val := sec.Key("ACCESS").String(); val != "" { - sec.Key("logger.access.MODE").MustString(val) - } - if sec.HasKey("ENABLE_ACCESS_LOG") && !sec.Key("ENABLE_ACCESS_LOG").MustBool() { - sec.Key("logger.access.MODE").SetValue("") - } + removedSettingWarning(rootCfg, "log", "ACCESS", "log", "logger.access.MODE", "1.21") + removedSettingWarning(rootCfg, "log", "ENABLE_ACCESS_LOG", "log", "logger.access.MODE", "1.21") + + removedSettingWarning(rootCfg, "log", "ROUTER", "log", "logger.router.MODE", "1.21") + removedSettingWarning(rootCfg, "log", "DISABLE_ROUTER_LOG", "log", "logger.router.MODE", "1.21") - deprecatedSetting(rootCfg, "log", "ROUTER", "log", "logger.router.MODE", "1.21") - deprecatedSetting(rootCfg, "log", "DISABLE_ROUTER_LOG", "log", "logger.router.MODE", "1.21") - if val := sec.Key("ROUTER").String(); val != "" { - sec.Key("logger.router.MODE").MustString(val) - } if !sec.HasKey("logger.router.MODE") { sec.Key("logger.router.MODE").MustString(",") // use default logger } - if sec.HasKey("DISABLE_ROUTER_LOG") && sec.Key("DISABLE_ROUTER_LOG").MustBool() { - sec.Key("logger.router.MODE").SetValue("") - } - deprecatedSetting(rootCfg, "log", "XORM", "log", "logger.xorm.MODE", "1.21") - deprecatedSetting(rootCfg, "log", "ENABLE_XORM_LOG", "log", "logger.xorm.MODE", "1.21") - if val := sec.Key("XORM").String(); val != "" { - sec.Key("logger.xorm.MODE").MustString(val) - } + removedSettingWarning(rootCfg, "log", "XORM", "log", "logger.xorm.MODE", "1.21") + removedSettingWarning(rootCfg, "log", "ENABLE_XORM_LOG", "log", "logger.xorm.MODE", "1.21") + if !sec.HasKey("logger.xorm.MODE") { sec.Key("logger.xorm.MODE").MustString(",") // use default logger } - if sec.HasKey("ENABLE_XORM_LOG") && !sec.Key("ENABLE_XORM_LOG").MustBool() { - sec.Key("logger.xorm.MODE").SetValue("") - } } func LogPrepareFilenameForWriter(fileName, defaultFileName string) string { diff --git a/modules/setting/mailer.go b/modules/setting/mailer.go index 4c3dff6850947..340ef3eef15f5 100644 --- a/modules/setting/mailer.go +++ b/modules/setting/mailer.go @@ -70,70 +70,25 @@ func loadMailerFrom(rootCfg ConfigProvider) { return } - // Handle Deprecations and map on to new configuration // DEPRECATED should not be removed because users maybe upgrade from lower version to the latest version // if these are removed, the warning will not be shown - deprecatedSetting(rootCfg, "mailer", "MAILER_TYPE", "mailer", "PROTOCOL", "v1.19.0") - if sec.HasKey("MAILER_TYPE") && !sec.HasKey("PROTOCOL") { - if sec.Key("MAILER_TYPE").String() == "sendmail" { - sec.Key("PROTOCOL").MustString("sendmail") - } - } + removedSettingWarning(rootCfg, "mailer", "MAILER_TYPE", "mailer", "PROTOCOL", "v1.19.0") - deprecatedSetting(rootCfg, "mailer", "HOST", "mailer", "SMTP_ADDR", "v1.19.0") - if sec.HasKey("HOST") && !sec.HasKey("SMTP_ADDR") { - givenHost := sec.Key("HOST").String() - addr, port, err := net.SplitHostPort(givenHost) - if err != nil && strings.Contains(err.Error(), "missing port in address") { - addr = givenHost - } else if err != nil { - log.Fatal("Invalid mailer.HOST (%s): %v", givenHost, err) - } - if addr == "" { - addr = "127.0.0.1" - } - sec.Key("SMTP_ADDR").MustString(addr) - sec.Key("SMTP_PORT").MustString(port) - } + removedSettingWarning(rootCfg, "mailer", "HOST", "mailer", "SMTP_ADDR", "v1.19.0") - deprecatedSetting(rootCfg, "mailer", "IS_TLS_ENABLED", "mailer", "PROTOCOL", "v1.19.0") - if sec.HasKey("IS_TLS_ENABLED") && !sec.HasKey("PROTOCOL") { - if sec.Key("IS_TLS_ENABLED").MustBool() { - sec.Key("PROTOCOL").MustString("smtps") - } else { - sec.Key("PROTOCOL").MustString("smtp+starttls") - } - } + removedSettingWarning(rootCfg, "mailer", "IS_TLS_ENABLED", "mailer", "PROTOCOL", "v1.19.0") - deprecatedSetting(rootCfg, "mailer", "DISABLE_HELO", "mailer", "ENABLE_HELO", "v1.19.0") - if sec.HasKey("DISABLE_HELO") && !sec.HasKey("ENABLE_HELO") { - sec.Key("ENABLE_HELO").MustBool(!sec.Key("DISABLE_HELO").MustBool()) - } + removedSettingWarning(rootCfg, "mailer", "DISABLE_HELO", "mailer", "ENABLE_HELO", "v1.19.0") - deprecatedSetting(rootCfg, "mailer", "SKIP_VERIFY", "mailer", "FORCE_TRUST_SERVER_CERT", "v1.19.0") - if sec.HasKey("SKIP_VERIFY") && !sec.HasKey("FORCE_TRUST_SERVER_CERT") { - sec.Key("FORCE_TRUST_SERVER_CERT").MustBool(sec.Key("SKIP_VERIFY").MustBool()) - } + removedSettingWarning(rootCfg, "mailer", "SKIP_VERIFY", "mailer", "FORCE_TRUST_SERVER_CERT", "v1.19.0") - deprecatedSetting(rootCfg, "mailer", "USE_CERTIFICATE", "mailer", "USE_CLIENT_CERT", "v1.19.0") - if sec.HasKey("USE_CERTIFICATE") && !sec.HasKey("USE_CLIENT_CERT") { - sec.Key("USE_CLIENT_CERT").MustBool(sec.Key("USE_CERTIFICATE").MustBool()) - } + removedSettingWarning(rootCfg, "mailer", "USE_CERTIFICATE", "mailer", "USE_CLIENT_CERT", "v1.19.0") - deprecatedSetting(rootCfg, "mailer", "CERT_FILE", "mailer", "CLIENT_CERT_FILE", "v1.19.0") - if sec.HasKey("CERT_FILE") && !sec.HasKey("CLIENT_CERT_FILE") { - sec.Key("CERT_FILE").MustString(sec.Key("CERT_FILE").String()) - } + removedSettingWarning(rootCfg, "mailer", "CERT_FILE", "mailer", "CLIENT_CERT_FILE", "v1.19.0") - deprecatedSetting(rootCfg, "mailer", "KEY_FILE", "mailer", "CLIENT_KEY_FILE", "v1.19.0") - if sec.HasKey("KEY_FILE") && !sec.HasKey("CLIENT_KEY_FILE") { - sec.Key("KEY_FILE").MustString(sec.Key("KEY_FILE").String()) - } + removedSettingWarning(rootCfg, "mailer", "KEY_FILE", "mailer", "CLIENT_KEY_FILE", "v1.19.0") - deprecatedSetting(rootCfg, "mailer", "ENABLE_HTML_ALTERNATIVE", "mailer", "SEND_AS_PLAIN_TEXT", "v1.19.0") - if sec.HasKey("ENABLE_HTML_ALTERNATIVE") && !sec.HasKey("SEND_AS_PLAIN_TEXT") { - sec.Key("SEND_AS_PLAIN_TEXT").MustBool(!sec.Key("ENABLE_HTML_ALTERNATIVE").MustBool(false)) - } + removedSettingWarning(rootCfg, "mailer", "ENABLE_HTML_ALTERNATIVE", "mailer", "SEND_AS_PLAIN_TEXT", "v1.19.0") if sec.HasKey("PROTOCOL") && sec.Key("PROTOCOL").String() == "smtp+startls" { log.Error("Deprecated fallback `[mailer]` `PROTOCOL = smtp+startls` present. Use `[mailer]` `PROTOCOL = smtp+starttls`` instead. This fallback will be removed in v1.19.0") diff --git a/modules/setting/mailer_test.go b/modules/setting/mailer_test.go index fbabf113786f7..b6d22dbdc12af 100644 --- a/modules/setting/mailer_test.go +++ b/modules/setting/mailer_test.go @@ -4,6 +4,8 @@ package setting import ( + "net" + "strings" "testing" "github.com/stretchr/testify/assert" @@ -20,7 +22,7 @@ func Test_loadMailerFrom(t *testing.T) { SMTPPort: "123", }, ":123": { - SMTPAddr: "127.0.0.1", + SMTPAddr: "", SMTPPort: "123", }, } @@ -29,7 +31,14 @@ func Test_loadMailerFrom(t *testing.T) { cfg, _ := NewConfigProviderFromData("") sec := cfg.Section("mailer") sec.NewKey("ENABLED", "true") - sec.NewKey("HOST", host) + if strings.Contains(host, ":") { + addr, port, err := net.SplitHostPort(host) + assert.NoError(t, err) + sec.NewKey("SMTP_ADDR", addr) + sec.NewKey("SMTP_PORT", port) + } else { + sec.NewKey("SMTP_ADDR", host) + } // Check mailer setting loadMailerFrom(cfg) diff --git a/modules/setting/mirror.go b/modules/setting/mirror.go index 3aa530a1f4847..aefe0455cd6b4 100644 --- a/modules/setting/mirror.go +++ b/modules/setting/mirror.go @@ -25,14 +25,9 @@ var Mirror = struct { } func loadMirrorFrom(rootCfg ConfigProvider) { - // Handle old configuration through `[repository]` `DISABLE_MIRRORS` - // - please note this was badly named and only disabled the creation of new pull mirrors // DEPRECATED should not be removed because users maybe upgrade from lower version to the latest version // if these are removed, the warning will not be shown - deprecatedSetting(rootCfg, "repository", "DISABLE_MIRRORS", "mirror", "ENABLED", "v1.19.0") - if ConfigSectionKeyBool(rootCfg.Section("repository"), "DISABLE_MIRRORS") { - Mirror.DisableNewPull = true - } + removedSettingWarning(rootCfg, "repository", "DISABLE_MIRRORS", "mirror", "ENABLED", "v1.19.0") if err := rootCfg.Section("mirror").MapTo(&Mirror); err != nil { log.Fatal("Failed to map Mirror settings: %v", err) diff --git a/modules/setting/oauth2.go b/modules/setting/oauth2.go index 0d3e63e0b4aa3..9465799abd9a8 100644 --- a/modules/setting/oauth2.go +++ b/modules/setting/oauth2.go @@ -121,10 +121,7 @@ func loadOAuth2From(rootCfg ConfigProvider) { } // Handle the rename of ENABLE to ENABLED - deprecatedSetting(rootCfg, "oauth2", "ENABLE", "oauth2", "ENABLED", "v1.23.0") - if sec.HasKey("ENABLE") && !sec.HasKey("ENABLED") { - OAuth2.Enabled = sec.Key("ENABLE").MustBool(OAuth2.Enabled) - } + removedSettingWarning(rootCfg, "oauth2", "ENABLE", "oauth2", "ENABLED", "v1.23.0") if !filepath.IsAbs(OAuth2.JWTSigningPrivateKeyFile) { OAuth2.JWTSigningPrivateKeyFile = filepath.Join(AppDataPath, OAuth2.JWTSigningPrivateKeyFile) diff --git a/modules/setting/server.go b/modules/setting/server.go index e15b790906738..1b124cda06b8b 100644 --- a/modules/setting/server.go +++ b/modules/setting/server.go @@ -174,8 +174,7 @@ func loadServerFrom(rootCfg ConfigProvider) { if sec.HasKey("ENABLE_ACME") { EnableAcme = sec.Key("ENABLE_ACME").MustBool(false) } else { - deprecatedSetting(rootCfg, "server", "ENABLE_LETSENCRYPT", "server", "ENABLE_ACME", "v1.19.0") - EnableAcme = sec.Key("ENABLE_LETSENCRYPT").MustBool(false) + removedSettingWarning(rootCfg, "server", "ENABLE_LETSENCRYPT", "server", "ENABLE_ACME", "v1.19.0") } Protocol = HTTP @@ -194,8 +193,7 @@ func loadServerFrom(rootCfg ConfigProvider) { if sec.HasKey("ACME_ACCEPTTOS") { AcmeTOS = sec.Key("ACME_ACCEPTTOS").MustBool(false) } else { - deprecatedSetting(rootCfg, "server", "LETSENCRYPT_ACCEPTTOS", "server", "ACME_ACCEPTTOS", "v1.19.0") - AcmeTOS = sec.Key("LETSENCRYPT_ACCEPTTOS").MustBool(false) + removedSettingWarning(rootCfg, "server", "LETSENCRYPT_ACCEPTTOS", "server", "ACME_ACCEPTTOS", "v1.19.0") } if !AcmeTOS { log.Fatal("ACME TOS is not accepted (ACME_ACCEPTTOS).") @@ -204,15 +202,13 @@ func loadServerFrom(rootCfg ConfigProvider) { if sec.HasKey("ACME_DIRECTORY") { AcmeLiveDirectory = sec.Key("ACME_DIRECTORY").MustString("https") } else { - deprecatedSetting(rootCfg, "server", "LETSENCRYPT_DIRECTORY", "server", "ACME_DIRECTORY", "v1.19.0") - AcmeLiveDirectory = sec.Key("LETSENCRYPT_DIRECTORY").MustString("https") + removedSettingWarning(rootCfg, "server", "LETSENCRYPT_DIRECTORY", "server", "ACME_DIRECTORY", "v1.19.0") } if sec.HasKey("ACME_EMAIL") { AcmeEmail = sec.Key("ACME_EMAIL").MustString("") } else { - deprecatedSetting(rootCfg, "server", "LETSENCRYPT_EMAIL", "server", "ACME_EMAIL", "v1.19.0") - AcmeEmail = sec.Key("LETSENCRYPT_EMAIL").MustString("") + removedSettingWarning(rootCfg, "server", "LETSENCRYPT_EMAIL", "server", "ACME_EMAIL", "v1.19.0") } if AcmeEmail == "" { log.Fatal("ACME Email is not set (ACME_EMAIL).") diff --git a/modules/setting/service.go b/modules/setting/service.go index 8c1843eeb7548..12f7e77a88130 100644 --- a/modules/setting/service.go +++ b/modules/setting/service.go @@ -152,9 +152,9 @@ func loadServiceFrom(rootCfg ConfigProvider) { } else { Service.RegisterManualConfirm = false } - if sec.HasKey("EMAIL_DOMAIN_WHITELIST") { - deprecatedSetting(rootCfg, "service", "EMAIL_DOMAIN_WHITELIST", "service", "EMAIL_DOMAIN_ALLOWLIST", "1.21") - } + + removedSettingWarning(rootCfg, "service", "EMAIL_DOMAIN_WHITELIST", "service", "EMAIL_DOMAIN_ALLOWLIST", "1.21") + Service.EmailDomainAllowList = CompileEmailGlobList(sec, "EMAIL_DOMAIN_WHITELIST", "EMAIL_DOMAIN_ALLOWLIST") Service.EmailDomainBlockList = CompileEmailGlobList(sec, "EMAIL_DOMAIN_BLOCKLIST") Service.ShowRegistrationButton = sec.Key("SHOW_REGISTRATION_BUTTON").MustBool(!(Service.DisableRegistration || Service.AllowOnlyExternalRegistration)) diff --git a/modules/setting/task.go b/modules/setting/task.go index f75b4f14813f8..cf0a59bf691a7 100644 --- a/modules/setting/task.go +++ b/modules/setting/task.go @@ -10,9 +10,9 @@ func loadTaskFrom(rootCfg ConfigProvider) { taskSec := rootCfg.Section("task") queueTaskSec := rootCfg.Section("queue.task") - deprecatedSetting(rootCfg, "task", "QUEUE_TYPE", "queue.task", "TYPE", "v1.19.0") - deprecatedSetting(rootCfg, "task", "QUEUE_CONN_STR", "queue.task", "CONN_STR", "v1.19.0") - deprecatedSetting(rootCfg, "task", "QUEUE_LENGTH", "queue.task", "LENGTH", "v1.19.0") + removedSettingWarning(rootCfg, "task", "QUEUE_TYPE", "queue.task", "TYPE", "v1.19.0") + removedSettingWarning(rootCfg, "task", "QUEUE_CONN_STR", "queue.task", "CONN_STR", "v1.19.0") + removedSettingWarning(rootCfg, "task", "QUEUE_LENGTH", "queue.task", "LENGTH", "v1.19.0") switch taskSec.Key("QUEUE_TYPE").MustString("channel") { case "channel":