conf_svr.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package http
  2. import (
  3. "go-common/app/admin/main/config/model"
  4. bm "go-common/library/net/http/blademaster"
  5. )
  6. func setToken(c *bm.Context) {
  7. res := map[string]interface{}{}
  8. v := new(model.SetTokenReq)
  9. err := c.Bind(v)
  10. if err != nil {
  11. return
  12. }
  13. if _, err = svr.AuthApp(c, user(c), c.Request.Header.Get("Cookie"), v.TreeID); err != nil {
  14. res["message"] = "服务树权限不足"
  15. c.JSONMap(res, err)
  16. return
  17. }
  18. // update & write cache
  19. if err = svr.SetToken(c, v.TreeID, v.Env, v.Zone, v.Token); err != nil {
  20. res["message"] = "重置token失败"
  21. c.JSONMap(res, err)
  22. return
  23. }
  24. c.JSON(nil, err)
  25. }
  26. // hosts client hosts
  27. func hosts(c *bm.Context) {
  28. res := map[string]interface{}{}
  29. v := new(model.HostsReq)
  30. err := c.Bind(v)
  31. if err != nil {
  32. return
  33. }
  34. if _, err = svr.AuthApp(c, user(c), c.Request.Header.Get("Cookie"), v.TreeID); err != nil {
  35. res["message"] = "服务树权限不足"
  36. c.JSONMap(res, err)
  37. return
  38. }
  39. c.JSON(svr.Hosts(c, v.TreeID, v.App, v.Env, v.Zone))
  40. }
  41. //clear host in redis
  42. func clearhost(c *bm.Context) {
  43. res := map[string]interface{}{}
  44. v := new(model.HostsReq)
  45. err := c.Bind(v)
  46. if err != nil {
  47. return
  48. }
  49. if _, err = svr.AuthApp(c, user(c), c.Request.Header.Get("Cookie"), v.TreeID); err != nil {
  50. res["message"] = "服务树权限不足"
  51. c.JSONMap(res, err)
  52. return
  53. }
  54. c.JSON(nil, svr.ClearHost(c, v.TreeID, v.Env, v.Zone))
  55. }