mirror of
https://gitea.com/gitea/tea.git
synced 2026-02-22 06:13:32 +01:00
Split up Context (#873)
Reviewed-on: https://gitea.com/gitea/tea/pulls/873 Co-authored-by: techknowlogick <techknowlogick@gitea.com> Co-committed-by: techknowlogick <techknowlogick@gitea.com>
This commit is contained in:
committed by
techknowlogick
parent
629872d1e9
commit
c2180048a0
49
modules/context/context_login.go
Normal file
49
modules/context/context_login.go
Normal file
@@ -0,0 +1,49 @@
|
||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package context
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/tea/modules/config"
|
||||
)
|
||||
|
||||
// GetLoginByEnvVar returns a login based on environment variables, or nil if no login can be created
|
||||
func GetLoginByEnvVar() *config.Login {
|
||||
var token string
|
||||
|
||||
giteaToken := os.Getenv("GITEA_TOKEN")
|
||||
githubToken := os.Getenv("GH_TOKEN")
|
||||
giteaInstanceURL := os.Getenv("GITEA_INSTANCE_URL")
|
||||
instanceInsecure := os.Getenv("GITEA_INSTANCE_INSECURE")
|
||||
insecure := false
|
||||
if len(instanceInsecure) > 0 {
|
||||
insecure, _ = strconv.ParseBool(instanceInsecure)
|
||||
}
|
||||
|
||||
// if no tokens are set, or no instance url for gitea fail fast
|
||||
if len(giteaInstanceURL) == 0 || (len(giteaToken) == 0 && len(githubToken) == 0) {
|
||||
return nil
|
||||
}
|
||||
|
||||
token = giteaToken
|
||||
if len(giteaToken) == 0 {
|
||||
token = githubToken
|
||||
}
|
||||
|
||||
return &config.Login{
|
||||
Name: "GITEA_LOGIN_VIA_ENV",
|
||||
URL: giteaInstanceURL,
|
||||
Token: token,
|
||||
Insecure: insecure,
|
||||
SSHKey: "",
|
||||
SSHCertPrincipal: "",
|
||||
SSHKeyFingerprint: "",
|
||||
SSHAgent: false,
|
||||
Created: time.Now().Unix(),
|
||||
VersionCheck: false,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user