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.

46 lines
1.3 KiB

  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/timeutil"
  9. "gitea.com/macaron/macaron"
  10. )
  11. // UpdatePublicKeyInRepo update public key and deploy key updates
  12. func UpdatePublicKeyInRepo(ctx *macaron.Context) {
  13. keyID := ctx.ParamsInt64(":id")
  14. repoID := ctx.ParamsInt64(":repoid")
  15. if err := models.UpdatePublicKeyUpdated(keyID); err != nil {
  16. ctx.JSON(500, map[string]interface{}{
  17. "err": err.Error(),
  18. })
  19. return
  20. }
  21. deployKey, err := models.GetDeployKeyByRepo(keyID, repoID)
  22. if err != nil {
  23. if models.IsErrDeployKeyNotExist(err) {
  24. ctx.PlainText(200, []byte("success"))
  25. return
  26. }
  27. ctx.JSON(500, map[string]interface{}{
  28. "err": err.Error(),
  29. })
  30. return
  31. }
  32. deployKey.UpdatedUnix = timeutil.TimeStampNow()
  33. if err = models.UpdateDeployKeyCols(deployKey, "updated_unix"); err != nil {
  34. ctx.JSON(500, map[string]interface{}{
  35. "err": err.Error(),
  36. })
  37. return
  38. }
  39. ctx.PlainText(200, []byte("success"))
  40. }