build.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package http
  2. import (
  3. "strings"
  4. "go-common/app/admin/main/config/model"
  5. "go-common/library/ecode"
  6. bm "go-common/library/net/http/blademaster"
  7. )
  8. func createBuild(c *bm.Context) {
  9. res := map[string]interface{}{}
  10. v := new(model.CreateBuildReq)
  11. err := c.Bind(v)
  12. if err != nil {
  13. return
  14. }
  15. name := user(c)
  16. if _, err = svr.AuthApp(c, name, c.Request.Header.Get("Cookie"), v.TreeID); err != nil {
  17. res["message"] = "服务树权限不足"
  18. c.JSONMap(res, err)
  19. return
  20. }
  21. if len(strings.TrimSpace(v.Name)) == 0 {
  22. res["message"] = "name不能为空"
  23. c.JSONMap(res, ecode.RequestErr)
  24. return
  25. }
  26. build := &model.Build{}
  27. build.TagID = v.TagID
  28. build.Operator = name
  29. build.Name = v.Name
  30. if err = svr.CreateBuild(build, v.TreeID, v.Env, v.Zone); err != nil {
  31. res["message"] = "创建build失败"
  32. c.JSONMap(res, err)
  33. return
  34. }
  35. c.JSON(nil, err)
  36. }
  37. func builds(c *bm.Context) {
  38. res := map[string]interface{}{}
  39. v := new(model.BuildsReq)
  40. err := c.Bind(v)
  41. if err != nil {
  42. return
  43. }
  44. if _, err = svr.AuthApp(c, user(c), c.Request.Header.Get("Cookie"), v.TreeID); err != nil {
  45. res["message"] = "服务树权限不足"
  46. c.JSONMap(res, err)
  47. return
  48. }
  49. c.JSON(svr.Builds(v.TreeID, v.AppName, v.Env, v.Zone))
  50. }
  51. func build(c *bm.Context) {
  52. res := map[string]interface{}{}
  53. v := new(model.BuildReq)
  54. err := c.Bind(v)
  55. if err != nil {
  56. return
  57. }
  58. if _, err = svr.AuthApps(c, user(c), c.Request.Header.Get("Cookie")); err != nil {
  59. res["message"] = "服务树权限不足"
  60. c.JSONMap(res, err)
  61. return
  62. }
  63. c.JSON(svr.Build(v.BuildID))
  64. }
  65. func buildDel(c *bm.Context) {
  66. res := map[string]interface{}{}
  67. v := new(model.BuildReq)
  68. err := c.Bind(v)
  69. if err != nil {
  70. return
  71. }
  72. if _, err = svr.AuthApps(c, user(c), c.Request.Header.Get("Cookie")); err != nil {
  73. res["message"] = "服务树权限不足"
  74. c.JSONMap(res, err)
  75. return
  76. }
  77. if err = svr.GetDelInfos(c, v.BuildID); err != nil {
  78. res["message"] = "主机列表中有正在使用该build的机器,请让主机离线3小时自动清除后再删除"
  79. c.JSONMap(res, err)
  80. return
  81. }
  82. if err = svr.Delete(v.BuildID); err != nil {
  83. res["message"] = "删除build失败"
  84. c.JSONMap(res, err)
  85. return
  86. }
  87. c.JSON(nil, err)
  88. }