From 9b2f38261b3a4564c64e360095a227f9ab1787d1 Mon Sep 17 00:00:00 2001 From: cassio zareck <121526696+cassiozareck@users.noreply.github.com> Date: Mon, 30 Dec 2024 02:54:20 -0300 Subject: [PATCH] Fix settings not being loaded at CLI (#26402) Closes #25898 The problem was that the default settings weren't being loaded --------- Signed-off-by: cassiozareck Co-authored-by: Lunny Xiao Co-authored-by: wxiaoguang (cherry picked from commit 1e2c8eb494ff5b8378653db5fed876d824ebca6f) Conflicts: modules/setting/indexer.go trivial context conflict --- cmd/admin_user_create.go | 4 ++++ cmd/web.go | 11 +++++++++++ modules/setting/cors.go | 5 ----- modules/setting/indexer.go | 2 +- modules/setting/mailer.go | 4 ---- modules/setting/session.go | 2 -- modules/setting/time.go | 1 - 7 files changed, 16 insertions(+), 13 deletions(-) diff --git a/cmd/admin_user_create.go b/cmd/admin_user_create.go index dfc484aeb2..781148e734 100644 --- a/cmd/admin_user_create.go +++ b/cmd/admin_user_create.go @@ -69,6 +69,10 @@ var microcmdUserCreate = &cli.Command{ } func runCreateUser(c *cli.Context) error { + // this command highly depends on the many setting options (create org, visibility, etc.), so it must have a full setting load first + // duplicate setting loading should be safe at the moment, but it should be refactored & improved in the future. + setting.LoadSettings() + if err := argsSet(c, "email"); err != nil { return err } diff --git a/cmd/web.go b/cmd/web.go index 44babd51c5..3fc64f7748 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -12,6 +12,7 @@ import ( "path/filepath" "strconv" "strings" + "time" _ "net/http/pprof" // Used for debugging if enabled and a web server is running @@ -115,6 +116,16 @@ func showWebStartupMessage(msg string) { log.Info("* CustomPath: %s", setting.CustomPath) log.Info("* ConfigFile: %s", setting.CustomConf) log.Info("%s", msg) // show startup message + + if setting.CORSConfig.Enabled { + log.Info("CORS Service Enabled") + } + if setting.DefaultUILocation != time.Local { + log.Info("Default UI Location is %v", setting.DefaultUILocation.String()) + } + if setting.MailService != nil { + log.Info("Mail Service Enabled: RegisterEmailConfirm=%v, Service.EnableNotifyMail=%v", setting.Service.RegisterEmailConfirm, setting.Service.EnableNotifyMail) + } } func serveInstall(ctx *cli.Context) error { diff --git a/modules/setting/cors.go b/modules/setting/cors.go index 63daaad60b..5260887d9d 100644 --- a/modules/setting/cors.go +++ b/modules/setting/cors.go @@ -5,8 +5,6 @@ package setting import ( "time" - - "code.gitea.io/gitea/modules/log" ) // CORSConfig defines CORS settings @@ -28,7 +26,4 @@ var CORSConfig = struct { func loadCorsFrom(rootCfg ConfigProvider) { mustMapSetting(rootCfg, "cors", &CORSConfig) - if CORSConfig.Enabled { - log.Info("CORS Service Enabled") - } } diff --git a/modules/setting/indexer.go b/modules/setting/indexer.go index 3c96b58740..4c4f63bc61 100644 --- a/modules/setting/indexer.go +++ b/modules/setting/indexer.go @@ -109,7 +109,7 @@ func IndexerGlobFromString(globstr string) []Glob { expr = strings.TrimSpace(expr) if expr != "" { if g, err := glob.Compile(expr, '.', '/'); err != nil { - log.Info("Invalid glob expression '%s' (skipped): %v", expr, err) + log.Warn("Invalid glob expression '%s' (skipped): %v", expr, err) } else { extarr = append(extarr, Glob{glob: g, pattern: expr}) } diff --git a/modules/setting/mailer.go b/modules/setting/mailer.go index 136d932b8d..0804fbd717 100644 --- a/modules/setting/mailer.go +++ b/modules/setting/mailer.go @@ -263,8 +263,6 @@ func loadMailerFrom(rootCfg ConfigProvider) { MailService.OverrideEnvelopeFrom = true MailService.EnvelopeFrom = parsed.Address } - - log.Info("Mail Service Enabled") } func loadRegisterMailFrom(rootCfg ConfigProvider) { @@ -275,7 +273,6 @@ func loadRegisterMailFrom(rootCfg ConfigProvider) { return } Service.RegisterEmailConfirm = true - log.Info("Register Mail Service Enabled") } func loadNotifyMailFrom(rootCfg ConfigProvider) { @@ -286,7 +283,6 @@ func loadNotifyMailFrom(rootCfg ConfigProvider) { return } Service.EnableNotifyMail = true - log.Info("Notify Mail Service Enabled") } func tryResolveAddr(addr string) []net.IPAddr { diff --git a/modules/setting/session.go b/modules/setting/session.go index e9637fdfc5..29ee67914d 100644 --- a/modules/setting/session.go +++ b/modules/setting/session.go @@ -73,6 +73,4 @@ func loadSessionFrom(rootCfg ConfigProvider) { SessionConfig.ProviderConfig = string(shadowConfig) SessionConfig.OriginalProvider = SessionConfig.Provider SessionConfig.Provider = "VirtualSession" - - log.Info("Session Service Enabled") } diff --git a/modules/setting/time.go b/modules/setting/time.go index 39acba12ef..97988211a9 100644 --- a/modules/setting/time.go +++ b/modules/setting/time.go @@ -20,7 +20,6 @@ func loadTimeFrom(rootCfg ConfigProvider) { if err != nil { log.Fatal("Load time zone failed: %v", err) } - log.Info("Default UI Location is %v", zone) } if DefaultUILocation == nil { DefaultUILocation = time.Local