You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

signing.go 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package misc
  2. import (
  3. "fmt"
  4. "net/http"
  5. "code.gitea.io/gitea/models"
  6. "code.gitea.io/gitea/modules/context"
  7. "code.gitea.io/gitea/modules/log"
  8. )
  9. // SigningKey returns the public key of the default signing key if it exists
  10. func SigningKey(ctx *context.Context) {
  11. // swagger:operation GET /signing-key.gpg miscellaneous getSigningKey
  12. // ---
  13. // summary: Get default signing-key.gpg
  14. // produces:
  15. // - text/plain
  16. // responses:
  17. // "200":
  18. // description: "GPG armored public key"
  19. // schema:
  20. // type: string
  21. // swagger:operation GET /repos/{owner}/{repo}/signing-key.gpg repository repoSigningKey
  22. // ---
  23. // summary: Get signing-key.gpg for given repository
  24. // produces:
  25. // - text/plain
  26. // parameters:
  27. // - name: owner
  28. // in: path
  29. // description: owner of the repo
  30. // type: string
  31. // required: true
  32. // - name: repo
  33. // in: path
  34. // description: name of the repo
  35. // type: string
  36. // required: true
  37. // responses:
  38. // "200":
  39. // description: "GPG armored public key"
  40. // schema:
  41. // type: string
  42. path := ""
  43. if ctx.Repo != nil && ctx.Repo.Repository != nil {
  44. path = ctx.Repo.Repository.RepoPath()
  45. }
  46. content, err := models.PublicSigningKey(path)
  47. if err != nil {
  48. ctx.ServerError("gpg export", err)
  49. return
  50. }
  51. _, err = ctx.Write([]byte(content))
  52. if err != nil {
  53. log.Error("Error writing key content %v", err)
  54. ctx.Error(http.StatusInternalServerError, fmt.Sprintf("%v", err))
  55. }
  56. }