mirror of
https://gitea.com/gitea/tea.git
synced 2025-09-03 18:38:29 +02:00
Add temporary authentication via environment variables (#639)
#633 Co-authored-by: Tim Riedl <mail@tim-riedl.de> Co-authored-by: techknowlogick <techknowlogick@noreply.gitea.com> Co-authored-by: Lunny Xiao <lunny@noreply.gitea.com> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-on: https://gitea.com/gitea/tea/pulls/639 Co-authored-by: Tim Riedl <uvulpos@noreply.gitea.com> Co-committed-by: Tim Riedl <uvulpos@noreply.gitea.com>
This commit is contained in:

committed by
techknowlogick

parent
449b2e3117
commit
d2ccead88b
38
modules/utils/validate.go
Normal file
38
modules/utils/validate.go
Normal file
@ -0,0 +1,38 @@
|
||||
// Copyright 2024 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// ValidateAuthenticationMethod checks the provided authentication method parameters
|
||||
func ValidateAuthenticationMethod(
|
||||
giteaURL string,
|
||||
token string,
|
||||
user string,
|
||||
passwd string,
|
||||
sshAgent bool,
|
||||
sshKey string,
|
||||
sshCertPrincipal string,
|
||||
) (*url.URL, error) {
|
||||
// Normalize URL
|
||||
serverURL, err := NormalizeURL(giteaURL)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Unable to parse URL: %s", err)
|
||||
}
|
||||
|
||||
if !sshAgent && sshCertPrincipal == "" && sshKey == "" {
|
||||
// .. if we have enough information to authenticate
|
||||
if len(token) == 0 && (len(user)+len(passwd)) == 0 {
|
||||
return nil, fmt.Errorf("No token set")
|
||||
} else if len(user) != 0 && len(passwd) == 0 {
|
||||
return nil, fmt.Errorf("No password set")
|
||||
} else if len(user) == 0 && len(passwd) != 0 {
|
||||
return nil, fmt.Errorf("No user set")
|
||||
}
|
||||
}
|
||||
return serverURL, nil
|
||||
}
|
Reference in New Issue
Block a user