key.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // Copyright 2015 The Gogs 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 repo
  5. import (
  6. "fmt"
  7. api "github.com/gogs/go-gogs-client"
  8. "github.com/gogs/gogs/models"
  9. "github.com/gogs/gogs/pkg/context"
  10. "github.com/gogs/gogs/pkg/setting"
  11. "github.com/gogs/gogs/routes/api/v1/convert"
  12. )
  13. func composeDeployKeysAPILink(repoPath string) string {
  14. return setting.AppURL + "api/v1/repos/" + repoPath + "/keys/"
  15. }
  16. // https://github.com/gogs/go-gogs-client/wiki/Repositories-Deploy-Keys#list-deploy-keys
  17. func ListDeployKeys(c *context.APIContext) {
  18. keys, err := models.ListDeployKeys(c.Repo.Repository.ID)
  19. if err != nil {
  20. c.Error(500, "ListDeployKeys", err)
  21. return
  22. }
  23. apiLink := composeDeployKeysAPILink(c.Repo.Owner.Name + "/" + c.Repo.Repository.Name)
  24. apiKeys := make([]*api.DeployKey, len(keys))
  25. for i := range keys {
  26. if err = keys[i].GetContent(); err != nil {
  27. c.Error(500, "GetContent", err)
  28. return
  29. }
  30. apiKeys[i] = convert.ToDeployKey(apiLink, keys[i])
  31. }
  32. c.JSON(200, &apiKeys)
  33. }
  34. // https://github.com/gogs/go-gogs-client/wiki/Repositories-Deploy-Keys#get-a-deploy-key
  35. func GetDeployKey(c *context.APIContext) {
  36. key, err := models.GetDeployKeyByID(c.ParamsInt64(":id"))
  37. if err != nil {
  38. if models.IsErrDeployKeyNotExist(err) {
  39. c.Status(404)
  40. } else {
  41. c.Error(500, "GetDeployKeyByID", err)
  42. }
  43. return
  44. }
  45. if err = key.GetContent(); err != nil {
  46. c.Error(500, "GetContent", err)
  47. return
  48. }
  49. apiLink := composeDeployKeysAPILink(c.Repo.Owner.Name + "/" + c.Repo.Repository.Name)
  50. c.JSON(200, convert.ToDeployKey(apiLink, key))
  51. }
  52. func HandleCheckKeyStringError(c *context.APIContext, err error) {
  53. if models.IsErrKeyUnableVerify(err) {
  54. c.Error(422, "", "Unable to verify key content")
  55. } else {
  56. c.Error(422, "", fmt.Errorf("Invalid key content: %v", err))
  57. }
  58. }
  59. func HandleAddKeyError(c *context.APIContext, err error) {
  60. switch {
  61. case models.IsErrKeyAlreadyExist(err):
  62. c.Error(422, "", "Key content has been used as non-deploy key")
  63. case models.IsErrKeyNameAlreadyUsed(err):
  64. c.Error(422, "", "Key title has been used")
  65. default:
  66. c.Error(500, "AddKey", err)
  67. }
  68. }
  69. // https://github.com/gogs/go-gogs-client/wiki/Repositories-Deploy-Keys#add-a-new-deploy-key
  70. func CreateDeployKey(c *context.APIContext, form api.CreateKeyOption) {
  71. content, err := models.CheckPublicKeyString(form.Key)
  72. if err != nil {
  73. HandleCheckKeyStringError(c, err)
  74. return
  75. }
  76. key, err := models.AddDeployKey(c.Repo.Repository.ID, form.Title, content)
  77. if err != nil {
  78. HandleAddKeyError(c, err)
  79. return
  80. }
  81. key.Content = content
  82. apiLink := composeDeployKeysAPILink(c.Repo.Owner.Name + "/" + c.Repo.Repository.Name)
  83. c.JSON(201, convert.ToDeployKey(apiLink, key))
  84. }
  85. // https://github.com/gogs/go-gogs-client/wiki/Repositories-Deploy-Keys#remove-a-deploy-key
  86. func DeleteDeploykey(c *context.APIContext) {
  87. if err := models.DeleteDeployKey(c.User, c.ParamsInt64(":id")); err != nil {
  88. if models.IsErrKeyAccessDenied(err) {
  89. c.Error(403, "", "You do not have access to this key")
  90. } else {
  91. c.Error(500, "DeleteDeployKey", err)
  92. }
  93. return
  94. }
  95. c.Status(204)
  96. }
PANIC: session(release): write data/sessions/3/6/36629a1cac22b6eb: no space left on device

PANIC

session(release): write data/sessions/3/6/36629a1cac22b6eb: no space left on device
github.com/go-macaron/session@v0.0.0-20190805070824-1a3cdc6f5659/session.go:199 (0x8b2934)
gopkg.in/macaron.v1@v1.3.9/context.go:79 (0x83d0a0)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:157 (0x80ab07)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:135 (0x80a8a8)
gopkg.in/macaron.v1@v1.3.9/context.go:121 (0x83d1f8)
gopkg.in/macaron.v1@v1.3.9/context.go:112 (0x84fdb5)
gopkg.in/macaron.v1@v1.3.9/recovery.go:161 (0x84fda8)
gopkg.in/macaron.v1@v1.3.9/logger.go:40 (0x840c73)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:157 (0x80ab07)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:135 (0x80a8a8)
gopkg.in/macaron.v1@v1.3.9/context.go:121 (0x83d1f8)
gopkg.in/macaron.v1@v1.3.9/router.go:187 (0x850fc6)
gopkg.in/macaron.v1@v1.3.9/router.go:303 (0x8493e5)
gopkg.in/macaron.v1@v1.3.9/macaron.go:220 (0x841fca)
net/http/server.go:2836 (0x7a79b2)
net/http/server.go:1924 (0x7a341b)
runtime/asm_amd64.s:1373 (0x46f9f0)