mirror of
https://gitea.com/gitea/tea.git
synced 2026-09-15 11:28:11 +02:00
Implements #1087. Adds `tea login status [<login name>] [-o <format>]`, which verifies the stored token for one or all configured logins and reports: - login name/URL and default status - whether the token is valid (via `GET /api/v1/user`) - auth method and token expiry - whether the git credential helper is configured Machine-readable output is available via the usual `-o` formats with fields `name`, `url`, `user`, `valid`, `auth_method`, `token_expiry`, `helper`, and `default`. Reviewed-on: https://gitea.com/gitea/tea/pulls/1105 Reviewed-by: bircni <bircni@icloud.com>
This commit is contained in:
@@ -48,6 +48,29 @@ func SetupHelper(login config.Login) (ok bool, err error) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// HasGitCredentialHelper reports whether tea is registered as a git credential
|
||||
// helper for the given login. It mirrors the global git config lookup used by
|
||||
// SetupHelper.
|
||||
func HasGitCredentialHelper(login config.Login) bool {
|
||||
if login.URL == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
helperKey := fmt.Sprintf("credential.%s.helper", login.URL)
|
||||
currentHelpers, err := exec.Command("git", "config", "--global", "--get-all", helperKey).Output()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
for _, line := range strings.Split(strings.ReplaceAll(string(currentHelpers), "\r", ""), "\n") {
|
||||
if strings.HasSuffix(strings.TrimSpace(line), "login helper") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// CreateLogin create a login to be stored in config
|
||||
func CreateLogin(ctx stdctx.Context, name, token, user, passwd, otp, scopes, sshKey, giteaURL, sshCertPrincipal, sshKeyFingerprint string, insecure, sshAgent, versionCheck, addHelper bool) error {
|
||||
// checks ...
|
||||
|
||||
Reference in New Issue
Block a user