key.go 3.2 KB

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

PANIC

session(release): write data/sessions/a/7/a75a0174b4a64142: 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)