Skip to content

Commit a5d0246

Browse files
wxiaoguangGiteaBot
andauthored
Avoid polluting the config (#25345)
Caught by #25330 Co-authored-by: Giteabot <[email protected]>
1 parent 695f5d1 commit a5d0246

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

modules/setting/mirror.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func loadMirrorFrom(rootCfg ConfigProvider) {
3030
// DEPRECATED should not be removed because users maybe upgrade from lower version to the latest version
3131
// if these are removed, the warning will not be shown
3232
deprecatedSetting(rootCfg, "repository", "DISABLE_MIRRORS", "mirror", "ENABLED", "v1.19.0")
33-
if rootCfg.Section("repository").Key("DISABLE_MIRRORS").MustBool(false) {
33+
if ConfigSectionKeyBool(rootCfg.Section("repository"), "DISABLE_MIRRORS") {
3434
Mirror.DisableNewPull = true
3535
}
3636

modules/setting/oauth2.go

+14-12
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,20 @@ func loadOAuth2From(rootCfg ConfigProvider) {
120120
OAuth2.JWTSigningPrivateKeyFile = filepath.Join(AppDataPath, OAuth2.JWTSigningPrivateKeyFile)
121121
}
122122

123-
key := make([]byte, 32)
124-
n, err := base64.RawURLEncoding.Decode(key, []byte(OAuth2.JWTSecretBase64))
125-
if err != nil || n != 32 {
126-
key, err = generate.NewJwtSecret()
127-
if err != nil {
128-
log.Fatal("error generating JWT secret: %v", err)
129-
}
130-
131-
secretBase64 := base64.RawURLEncoding.EncodeToString(key)
132-
rootCfg.Section("oauth2").Key("JWT_SECRET").SetValue(secretBase64)
133-
if err := rootCfg.Save(); err != nil {
134-
log.Fatal("save oauth2.JWT_SECRET failed: %v", err)
123+
if InstallLock {
124+
key := make([]byte, 32)
125+
n, err := base64.RawURLEncoding.Decode(key, []byte(OAuth2.JWTSecretBase64))
126+
if err != nil || n != 32 {
127+
key, err = generate.NewJwtSecret()
128+
if err != nil {
129+
log.Fatal("error generating JWT secret: %v", err)
130+
}
131+
132+
secretBase64 := base64.RawURLEncoding.EncodeToString(key)
133+
rootCfg.Section("oauth2").Key("JWT_SECRET").SetValue(secretBase64)
134+
if err := rootCfg.Save(); err != nil {
135+
log.Fatal("save oauth2.JWT_SECRET failed: %v", err)
136+
}
135137
}
136138
}
137139
}

modules/setting/setting.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ func loadRunModeFrom(rootCfg ConfigProvider) {
262262
RunUser = rootSec.Key("RUN_USER").MustString(user.CurrentUsername())
263263
// The following is a purposefully undocumented option. Please do not run Gitea as root. It will only cause future headaches.
264264
// Please don't use root as a bandaid to "fix" something that is broken, instead the broken thing should instead be fixed properly.
265-
unsafeAllowRunAsRoot := rootSec.Key("I_AM_BEING_UNSAFE_RUNNING_AS_ROOT").MustBool(false)
265+
unsafeAllowRunAsRoot := ConfigSectionKeyBool(rootSec, "I_AM_BEING_UNSAFE_RUNNING_AS_ROOT")
266266
RunMode = os.Getenv("GITEA_RUN_MODE")
267267
if RunMode == "" {
268268
RunMode = rootSec.Key("RUN_MODE").MustString("prod")

0 commit comments

Comments
 (0)