本站源代码
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

60 lines
1.8KB

  1. // Copyright 2015 The Gogs Authors. All rights reserved.
  2. // Copyright 2017 The Gitea Authors. All rights reserved.
  3. // Use of this source code is governed by a MIT-style
  4. // license that can be found in the LICENSE file.
  5. package git
  6. import (
  7. "fmt"
  8. "strings"
  9. "code.gitea.io/gitea/modules/process"
  10. )
  11. // LoadPublicKeyContent will load the key from gpg
  12. func (gpgSettings *GPGSettings) LoadPublicKeyContent() error {
  13. content, stderr, err := process.GetManager().Exec(
  14. "gpg -a --export",
  15. "gpg", "-a", "--export", gpgSettings.KeyID)
  16. if err != nil {
  17. return fmt.Errorf("Unable to get default signing key: %s, %s, %v", gpgSettings.KeyID, stderr, err)
  18. }
  19. gpgSettings.PublicKeyContent = content
  20. return nil
  21. }
  22. // GetDefaultPublicGPGKey will return and cache the default public GPG settings for this repository
  23. func (repo *Repository) GetDefaultPublicGPGKey(forceUpdate bool) (*GPGSettings, error) {
  24. if repo.gpgSettings != nil && !forceUpdate {
  25. return repo.gpgSettings, nil
  26. }
  27. gpgSettings := &GPGSettings{
  28. Sign: true,
  29. }
  30. value, _ := NewCommand("config", "--get", "commit.gpgsign").RunInDir(repo.Path)
  31. sign, valid := ParseBool(strings.TrimSpace(value))
  32. if !sign || !valid {
  33. gpgSettings.Sign = false
  34. repo.gpgSettings = gpgSettings
  35. return gpgSettings, nil
  36. }
  37. signingKey, _ := NewCommand("config", "--get", "user.signingkey").RunInDir(repo.Path)
  38. gpgSettings.KeyID = strings.TrimSpace(signingKey)
  39. defaultEmail, _ := NewCommand("config", "--get", "user.email").RunInDir(repo.Path)
  40. gpgSettings.Email = strings.TrimSpace(defaultEmail)
  41. defaultName, _ := NewCommand("config", "--get", "user.name").RunInDir(repo.Path)
  42. gpgSettings.Name = strings.TrimSpace(defaultName)
  43. if err := gpgSettings.LoadPublicKeyContent(); err != nil {
  44. return nil, err
  45. }
  46. repo.gpgSettings = gpgSettings
  47. return repo.gpgSettings, nil
  48. }
上海开阖软件有限公司 沪ICP备12045867号-1