http.go 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/admin/main/aegis/conf"
  5. "go-common/app/admin/main/aegis/model"
  6. "go-common/app/admin/main/aegis/service"
  7. "go-common/library/log"
  8. bm "go-common/library/net/http/blademaster"
  9. "go-common/library/net/http/blademaster/middleware/permit"
  10. "go-common/library/net/http/blademaster/middleware/verify"
  11. )
  12. var (
  13. srv *service.Service
  14. vfy *verify.Verify
  15. authSvr *permit.Permit
  16. )
  17. // Init init
  18. func Init(c *conf.Config, s *service.Service) {
  19. srv = s
  20. vfy = verify.New(c.Verify)
  21. authSvr = permit.New(c.Auth)
  22. engine := bm.DefaultServer(c.BM)
  23. route(engine)
  24. if err := engine.Start(); err != nil {
  25. log.Error("bm Start error(%v)", err)
  26. panic(err)
  27. }
  28. }
  29. func route(e *bm.Engine) {
  30. e.Ping(ping)
  31. e.GET("/x/admin/aegis/debug/cache", perm(""), cache)
  32. gb := e.Group("/x/admin/aegis/business", perm(""), preHandlerUser())
  33. {
  34. gb.GET("/view", checkBizAdmin(), getBusiness)
  35. gb.GET("/list", checkBizAdmin(), getBusinessList)
  36. gb.GET("/enable", checkBizBID(), getBusinessEnable)
  37. gb.POST("/add", authSvr.Permit("AEGIS_REGISTER"), addBusiness)
  38. gb.POST("/update", checkBizAdmin(), updateBusiness)
  39. gb.POST("/set", checkBizAdmin(), setBusinessState)
  40. gb.GET("config/list", listBizCFGs)
  41. gb.GET("config/reserve", reserveCFG)
  42. gb.POST("config/add", addBizCFG)
  43. gb.POST("config/update", updateBizCFG)
  44. }
  45. gt := e.Group("/x/admin/aegis/task", perm(""), preHandlerUser(), checkTaskRole())
  46. {
  47. gt.POST("/delay", taskDelay)
  48. gt.POST("/release", taskRelease)
  49. gt.POST("/consumer/on", consumerOn)
  50. gt.POST("/consumer/off", consumerOff)
  51. gt.POST("/consumer/kickout", kickOut)
  52. gt.GET("/undostat", taskUnDo)
  53. gt.GET("/stat", taskStat)
  54. }
  55. gtc := e.Group("/x/admin/aegis/task/config", perm(""), preHandlerUser(), checkBizID())
  56. {
  57. gtc.GET("/maxweight", maxWeight)
  58. gtc.GET("/list", configList)
  59. gtc.POST("/delete", configDelete)
  60. gtc.POST("/add", configAdd)
  61. gtc.POST("/edit", configEdit)
  62. gtc.POST("/set", configSet)
  63. gtc.GET("/weightlog", weightlog)
  64. }
  65. engineTask := e.Group("/x/admin/aegis/engine", perm(""), preHandlerUser(), checkTaskRole())
  66. {
  67. // 任务列表操作
  68. engineTask.GET("/task/next", checkon(), next)
  69. engineTask.GET("/task/info", infoByTask)
  70. engineTask.GET("/task/list", listByTask)
  71. }
  72. engineRsc := e.Group("/x/admin/aegis/engine", perm(""), preHandlerUser())
  73. {
  74. engineRsc.POST("/submit", checkBizBID(), submit)
  75. // 任务列表下面的flow列表
  76. engineRsc.GET("/task/listbizflow", checkAccessTask(), listBizFlow)
  77. // 资源列表操作
  78. engineRsc.GET("/resource/info", checkBizBID(), infoByResource)
  79. engineRsc.GET("/resource/list", checkBizBID(), listByResource)
  80. engineRsc.POST("/resource/batchsubmit", checkBizLeader(), batchSubmit)
  81. //跳流程
  82. engineRsc.GET("/resource/listforjump", checkBizBID(), listforjump)
  83. engineRsc.POST("/resource/jump", checkBizBID(), jump)
  84. // 封禁相关
  85. engineRsc.POST("/forbid/img/upload", upload)
  86. //信息追踪
  87. engineRsc.GET("/track", checkBizBID(), track)
  88. //操作日志
  89. engineRsc.GET("/auditlog", checkBizBID(), auditLog)
  90. engineRsc.GET("/auditlog/csv", checkBizBID(), auditLogCSV)
  91. //权限查询
  92. engineRsc.GET("/auth", auth)
  93. //手动取消, 运营人员权限
  94. engineRsc.GET("/cancel", checkBizOper(), cancelByOper)
  95. }
  96. gn := e.Group("/x/admin/aegis/net", perm(""), checkBizID())
  97. {
  98. gn.GET("", listNet)
  99. gn.GET("/svg", svg)
  100. gn.GET("/nets", getNetByBusiness)
  101. gn.GET("/show", showNet)
  102. gn.POST("/add", addNet)
  103. gn.POST("/update", updateNet)
  104. gn.POST("/switch", switchNet)
  105. gto := gn.Group("/token")
  106. {
  107. gto.GET("", listToken)
  108. gto.GET("/groups", tokenGroupByType)
  109. gto.GET("/config", configToken)
  110. gto.GET("/show", showToken)
  111. gto.POST("/add", addToken)
  112. }
  113. gf := gn.Group("/flow")
  114. {
  115. gf.GET("", listFlow)
  116. gf.GET("/flows", getFlowByNet)
  117. gf.GET("/show", showFlow)
  118. gf.POST("/add", addFlow)
  119. gf.POST("/update", updateFlow)
  120. gf.POST("/switch", switchFlow)
  121. }
  122. gtr := gn.Group("/transition")
  123. {
  124. gtr.GET("", listTransition)
  125. gtr.GET("/trans", getTranByNet)
  126. gtr.GET("/show", showTransition)
  127. gtr.POST("/add", addTransition)
  128. gtr.POST("/update", updateTransition)
  129. gtr.POST("/switch", switchTransition)
  130. }
  131. gd := gn.Group("/direction")
  132. {
  133. gd.GET("", listDirection)
  134. gd.GET("/show", showDirection)
  135. gd.POST("/add", addDirection)
  136. gd.POST("/update", updateDirection)
  137. gd.POST("/switch", switchDirection)
  138. }
  139. }
  140. rt := e.Group("/x/admin/aegis/report", perm(""), preHandlerUser(), checkBizLeader())
  141. {
  142. rt.GET("/task/flow", taskflow)
  143. rt.GET("/task/flow/csv", taskflowCSV)
  144. rt.GET("/task/submit", taskSubmit)
  145. rt.GET("/task/submit/csv", taskSubmitCSV)
  146. rt.GET("/business/flows", getBizFlow)
  147. }
  148. e.GET("/x/admin/aegis/net/token/byname", perm(""), checkBizBIDBiz(), tokenByName)
  149. e.GET("/x/admin/aegis/task/role", perm(""), preHandlerUser(), role)
  150. e.POST("/x/admin/aegis/task/role/flush", roleFlush)
  151. e.GET("/x/admin/aegis/task/consumer/watch", consumerWatcher)
  152. e.POST("/x/internal/aegis/add", gray(), add)
  153. e.POST("/x/internal/aegis/cancel", cancel)
  154. e.POST("/x/internal/aegis/update", update)
  155. //监控平台
  156. gm := e.Group("/x/admin/aegis/monitor", perm(""))
  157. {
  158. gm.GET("/rule/result", perm("MONITOR_RULE_READ"), monitorRuleResult) //查看监控规则结果
  159. gm.POST("/rule/update", perm("MONITOR_RULE_EDIT"), monitorRuleUpdate) //修改监控规则
  160. }
  161. inter := e.Group("/x/internal/aegis", vfy.Verify)
  162. {
  163. inter.GET("/monitor/result/oids", monitorResultOids) //获取满足监控时间的对象id
  164. }
  165. }
  166. func ping(c *bm.Context) {
  167. if err := srv.Ping(c); err != nil {
  168. log.Error("ping error(%v)", err)
  169. c.AbortWithStatus(http.StatusServiceUnavailable)
  170. }
  171. }
  172. func uid(c *bm.Context) int64 {
  173. if v, exist := c.Get("uid"); exist {
  174. return v.(int64)
  175. }
  176. return 0
  177. }
  178. func uname(c *bm.Context) string {
  179. if v, exist := c.Get("username"); exist {
  180. return v.(string)
  181. }
  182. return ""
  183. }
  184. func perm(per string) bm.HandlerFunc {
  185. if srv.Debug() == "local" {
  186. return func(ctx *bm.Context) {}
  187. }
  188. return authSvr.Permit(per)
  189. }
  190. func gray() bm.HandlerFunc {
  191. return func(ctx *bm.Context) {
  192. opt := &model.AddOption{}
  193. ctx.Bind(opt)
  194. if !srv.Gray(opt) {
  195. log.Info("opt(%+v) not hit gray", opt)
  196. ctx.JSON(nil, nil)
  197. ctx.Abort()
  198. return
  199. }
  200. log.Info("opt(%+v) hit gray", opt)
  201. }
  202. }