mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-28 12:16:17 +01:00
Revert: auto generate INTERNAL_TOKEN (#21608)
Follow #19663 Some users do cluster deployment, they still depend on this auto-generating behavior. Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
parent
07178f4d0c
commit
e09025fdce
1 changed files with 19 additions and 0 deletions
|
@ -22,6 +22,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"code.gitea.io/gitea/modules/container"
|
"code.gitea.io/gitea/modules/container"
|
||||||
|
"code.gitea.io/gitea/modules/generate"
|
||||||
"code.gitea.io/gitea/modules/json"
|
"code.gitea.io/gitea/modules/json"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/user"
|
"code.gitea.io/gitea/modules/user"
|
||||||
|
@ -962,6 +963,11 @@ func loadFromConf(allowEmpty bool, extraConfig string) {
|
||||||
SuccessfulTokensCacheSize = sec.Key("SUCCESSFUL_TOKENS_CACHE_SIZE").MustInt(20)
|
SuccessfulTokensCacheSize = sec.Key("SUCCESSFUL_TOKENS_CACHE_SIZE").MustInt(20)
|
||||||
|
|
||||||
InternalToken = loadSecret(sec, "INTERNAL_TOKEN_URI", "INTERNAL_TOKEN")
|
InternalToken = loadSecret(sec, "INTERNAL_TOKEN_URI", "INTERNAL_TOKEN")
|
||||||
|
if InstallLock && InternalToken == "" {
|
||||||
|
// if Gitea has been installed but the InternalToken hasn't been generated (upgrade from an old release), we should generate
|
||||||
|
// some users do cluster deployment, they still depend on this auto-generating behavior.
|
||||||
|
generateSaveInternalToken()
|
||||||
|
}
|
||||||
|
|
||||||
cfgdata := sec.Key("PASSWORD_COMPLEXITY").Strings(",")
|
cfgdata := sec.Key("PASSWORD_COMPLEXITY").Strings(",")
|
||||||
if len(cfgdata) == 0 {
|
if len(cfgdata) == 0 {
|
||||||
|
@ -1182,6 +1188,19 @@ func loadSecret(sec *ini.Section, uriKey, verbatimKey string) string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// generateSaveInternalToken generates and saves the internal token to app.ini
|
||||||
|
func generateSaveInternalToken() {
|
||||||
|
token, err := generate.NewInternalToken()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Error generate internal token: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
InternalToken = token
|
||||||
|
CreateOrAppendToCustomConf("security.INTERNAL_TOKEN", func(cfg *ini.File) {
|
||||||
|
cfg.Section("security").Key("INTERNAL_TOKEN").SetValue(token)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// MakeAbsoluteAssetURL returns the absolute asset url prefix without a trailing slash
|
// MakeAbsoluteAssetURL returns the absolute asset url prefix without a trailing slash
|
||||||
func MakeAbsoluteAssetURL(appURL, staticURLPrefix string) string {
|
func MakeAbsoluteAssetURL(appURL, staticURLPrefix string) string {
|
||||||
parsedPrefix, err := url.Parse(strings.TrimSuffix(staticURLPrefix, "/"))
|
parsedPrefix, err := url.Parse(strings.TrimSuffix(staticURLPrefix, "/"))
|
||||||
|
|
Loading…
Reference in a new issue