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.

key.go 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // Copyright 2018 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. // Package private includes all internal routes. The package name internal is ideal but Golang is not allowed, so we use private as package name instead.
  5. package private
  6. import (
  7. "code.gitea.io/gitea/models"
  8. "code.gitea.io/gitea/modules/util"
  9. macaron "gopkg.in/macaron.v1"
  10. )
  11. // UpdateDeployKey update deploy key updates
  12. func UpdateDeployKey(ctx *macaron.Context) {
  13. repoID := ctx.ParamsInt64(":repoid")
  14. keyID := ctx.ParamsInt64(":keyid")
  15. deployKey, err := models.GetDeployKeyByRepo(keyID, repoID)
  16. if err != nil {
  17. ctx.JSON(500, map[string]interface{}{
  18. "err": err.Error(),
  19. })
  20. return
  21. }
  22. deployKey.UpdatedUnix = util.TimeStampNow()
  23. if err = models.UpdateDeployKeyCols(deployKey, "updated_unix"); err != nil {
  24. ctx.JSON(500, map[string]interface{}{
  25. "err": err.Error(),
  26. })
  27. return
  28. }
  29. ctx.PlainText(200, []byte("success"))
  30. }
  31. // UpdatePublicKey update publick key updates
  32. func UpdatePublicKey(ctx *macaron.Context) {
  33. keyID := ctx.ParamsInt64(":id")
  34. if err := models.UpdatePublicKeyUpdated(keyID); err != nil {
  35. ctx.JSON(500, map[string]interface{}{
  36. "err": err.Error(),
  37. })
  38. return
  39. }
  40. ctx.PlainText(200, []byte("success"))
  41. }
  42. //GetPublicKeyByID chainload to models.GetPublicKeyByID
  43. func GetPublicKeyByID(ctx *macaron.Context) {
  44. keyID := ctx.ParamsInt64(":id")
  45. key, err := models.GetPublicKeyByID(keyID)
  46. if err != nil {
  47. ctx.JSON(500, map[string]interface{}{
  48. "err": err.Error(),
  49. })
  50. return
  51. }
  52. ctx.JSON(200, key)
  53. }
  54. //GetUserByKeyID chainload to models.GetUserByKeyID
  55. func GetUserByKeyID(ctx *macaron.Context) {
  56. keyID := ctx.ParamsInt64(":id")
  57. user, err := models.GetUserByKeyID(keyID)
  58. if err != nil {
  59. ctx.JSON(500, map[string]interface{}{
  60. "err": err.Error(),
  61. })
  62. return
  63. }
  64. ctx.JSON(200, user)
  65. }
  66. //GetDeployKey chainload to models.GetDeployKey
  67. func GetDeployKey(ctx *macaron.Context) {
  68. repoID := ctx.ParamsInt64(":repoid")
  69. keyID := ctx.ParamsInt64(":keyid")
  70. dKey, err := models.GetDeployKeyByRepo(keyID, repoID)
  71. if err != nil {
  72. if models.IsErrDeployKeyNotExist(err) {
  73. ctx.JSON(404, []byte("not found"))
  74. return
  75. }
  76. ctx.JSON(500, map[string]interface{}{
  77. "err": err.Error(),
  78. })
  79. return
  80. }
  81. ctx.JSON(200, dKey)
  82. }
  83. //HasDeployKey chainload to models.HasDeployKey
  84. func HasDeployKey(ctx *macaron.Context) {
  85. repoID := ctx.ParamsInt64(":repoid")
  86. keyID := ctx.ParamsInt64(":keyid")
  87. if models.HasDeployKey(keyID, repoID) {
  88. ctx.PlainText(200, []byte("success"))
  89. return
  90. }
  91. ctx.PlainText(404, []byte("not found"))
  92. }