aboutsummaryrefslogtreecommitdiffstats
path: root/routers/install/install.go
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2022-11-04 04:55:09 +0800
committerGitHub <noreply@github.com>2022-11-03 20:55:09 +0000
commit4d1e2b8334b6f18b82ef4e646dd122200fb0b6c3 (patch)
tree5206d06ef008bbf7d02c1def0cfd75ddd0eea1d0 /routers/install/install.go
parent3e8618949e088cf3606a0b2ad4828953936d4247 (diff)
downloadgitea-4d1e2b8334b6f18b82ef4e646dd122200fb0b6c3.tar.gz
gitea-4d1e2b8334b6f18b82ef4e646dd122200fb0b6c3.zip
Fix token generation when using INTERNAL_TOKEN_URI (#21669)
Fix https://github.com/go-gitea/gitea/issues/21666 Caused by https://github.com/go-gitea/gitea/pull/19663 Before: when install, the INTERNAL_TOKEN was always generated and saved. But the internal token may be already there by INTERNAL_TOKEN_URI After: INTERNAL_TOKEN_URI file must be non-empty. When install, skip internal token generation if the token exists.
Diffstat (limited to 'routers/install/install.go')
-rw-r--r--routers/install/install.go14
1 files changed, 9 insertions, 5 deletions
diff --git a/routers/install/install.go b/routers/install/install.go
index 6bac5b5ff7..184dc5bae1 100644
--- a/routers/install/install.go
+++ b/routers/install/install.go
@@ -474,12 +474,16 @@ func SubmitInstall(ctx *context.Context) {
cfg.Section("security").Key("INSTALL_LOCK").SetValue("true")
- var internalToken string
- if internalToken, err = generate.NewInternalToken(); err != nil {
- ctx.RenderWithErr(ctx.Tr("install.internal_token_failed", err), tplInstall, &form)
- return
+ // the internal token could be read from INTERNAL_TOKEN or INTERNAL_TOKEN_URI (the file is guaranteed to be non-empty)
+ // if there is no InternalToken, generate one and save to security.INTERNAL_TOKEN
+ if setting.InternalToken == "" {
+ var internalToken string
+ if internalToken, err = generate.NewInternalToken(); err != nil {
+ ctx.RenderWithErr(ctx.Tr("install.internal_token_failed", err), tplInstall, &form)
+ return
+ }
+ cfg.Section("security").Key("INTERNAL_TOKEN").SetValue(internalToken)
}
- cfg.Section("security").Key("INTERNAL_TOKEN").SetValue(internalToken)
// if there is already a SECRET_KEY, we should not overwrite it, otherwise the encrypted data will not be able to be decrypted
if setting.SecretKey == "" {