Files
mayfly-go/server/internal/machine/router/machine.go

85 lines
2.3 KiB
Go
Raw Normal View History

package router
2021-04-16 15:10:07 +08:00
import (
2022-09-09 18:26:08 +08:00
"mayfly-go/internal/machine/api"
"mayfly-go/internal/machine/application"
2022-10-26 20:49:29 +08:00
tagapp "mayfly-go/internal/tag/application"
2023-01-14 16:29:52 +08:00
"mayfly-go/pkg/req"
2021-04-16 15:10:07 +08:00
"github.com/gin-gonic/gin"
)
func InitMachineRouter(router *gin.RouterGroup) {
m := &api.Machine{
2022-09-09 18:26:08 +08:00
MachineApp: application.GetMachineApp(),
2022-10-26 20:49:29 +08:00
TagApp: tagapp.GetTagTreeApp(),
}
machines := router.Group("machines")
2021-04-16 15:10:07 +08:00
{
machines.GET("", func(c *gin.Context) {
2023-01-14 16:29:52 +08:00
req.NewCtxWithGin(c).Handle(m.Machines)
2021-04-16 15:10:07 +08:00
})
machines.GET(":machineId/stats", func(c *gin.Context) {
2023-01-14 16:29:52 +08:00
req.NewCtxWithGin(c).Handle(m.MachineStats)
})
2022-01-16 21:45:00 +08:00
machines.GET(":machineId/process", func(c *gin.Context) {
2023-01-14 16:29:52 +08:00
req.NewCtxWithGin(c).Handle(m.GetProcess)
2022-01-16 21:45:00 +08:00
})
// 终止进程
2023-01-14 16:29:52 +08:00
killProcessL := req.NewLogInfo("终止进程").WithSave(true)
killProcessP := req.NewPermission("machine:killprocess")
2022-01-16 21:45:00 +08:00
machines.DELETE(":machineId/process", func(c *gin.Context) {
2023-01-14 16:29:52 +08:00
req.NewCtxWithGin(c).
2022-01-16 21:45:00 +08:00
WithLog(killProcessL).
WithRequiredPermission(killProcessP).
Handle(m.KillProcess)
})
2023-01-14 16:29:52 +08:00
saveMachine := req.NewLogInfo("保存机器信息").WithSave(true)
saveMachineP := req.NewPermission("machine:update")
machines.POST("", func(c *gin.Context) {
2023-01-14 16:29:52 +08:00
req.NewCtxWithGin(c).
WithLog(saveMachine).
WithRequiredPermission(saveMachineP).
Handle(m.SaveMachine)
})
machines.POST("test-conn", func(c *gin.Context) {
req.NewCtxWithGin(c).
Handle(m.TestConn)
})
2023-01-14 16:29:52 +08:00
changeStatus := req.NewLogInfo("调整机器状态").WithSave(true)
machines.PUT(":machineId/:status", func(c *gin.Context) {
2023-01-14 16:29:52 +08:00
req.NewCtxWithGin(c).
WithLog(changeStatus).
Handle(m.ChangeStatus)
})
2023-01-14 16:29:52 +08:00
delMachine := req.NewLogInfo("删除机器").WithSave(true)
machines.DELETE(":machineId", func(c *gin.Context) {
2023-01-14 16:29:52 +08:00
req.NewCtxWithGin(c).
WithLog(delMachine).
Handle(m.DeleteMachine)
2021-04-16 15:10:07 +08:00
})
2023-01-14 16:29:52 +08:00
closeCli := req.NewLogInfo("关闭机器客户端").WithSave(true)
machines.DELETE(":machineId/close-cli", func(c *gin.Context) {
2023-01-14 16:29:52 +08:00
req.NewCtxWithGin(c).WithLog(closeCli).Handle(m.CloseCli)
2021-04-16 15:10:07 +08:00
})
machines.GET(":machineId/terminal", m.WsSSH)
// 获取机器终端回放记录的相应文件夹名或文件名,目前具有保存机器信息的权限标识才有权限查看终端回放
machines.GET("rec/names", func(c *gin.Context) {
2023-01-14 16:29:52 +08:00
req.NewCtxWithGin(c).
WithRequiredPermission(saveMachineP).
Handle(m.MachineRecDirNames)
})
2021-04-16 15:10:07 +08:00
}
}