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

54 lines
1.6 KiB
Go
Raw Normal View History

package router
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"
"github.com/gin-gonic/gin"
)
func InitMachineScriptRouter(router *gin.RouterGroup) {
machines := router.Group("machines")
{
2021-09-11 14:04:09 +08:00
ms := &api.MachineScript{
2022-09-09 18:26:08 +08:00
MachineScriptApp: application.GetMachineScriptApp(),
MachineApp: application.GetMachineApp(),
2022-10-26 20:49:29 +08:00
TagApp: tagapp.GetTagTreeApp(),
}
// 获取指定机器脚本列表
machines.GET(":machineId/scripts", func(c *gin.Context) {
2023-01-14 16:29:52 +08:00
req.NewCtxWithGin(c).Handle(ms.MachineScripts)
})
2023-01-14 16:29:52 +08:00
saveMachienScriptLog := req.NewLogInfo("机器-保存脚本").WithSave(true)
smsP := req.NewPermission("machine:script:save")
// 保存脚本
machines.POST(":machineId/scripts", func(c *gin.Context) {
2023-01-14 16:29:52 +08:00
req.NewCtxWithGin(c).WithLog(saveMachienScriptLog).
2021-06-09 16:58:57 +08:00
WithRequiredPermission(smsP).
Handle(ms.SaveMachineScript)
})
2023-01-14 16:29:52 +08:00
deleteLog := req.NewLogInfo("机器-删除脚本").WithSave(true)
dP := req.NewPermission("machine:script:del")
// 保存脚本
machines.DELETE(":machineId/scripts/:scriptId", func(c *gin.Context) {
2023-01-14 16:29:52 +08:00
req.NewCtxWithGin(c).WithLog(deleteLog).
2021-06-09 16:58:57 +08:00
WithRequiredPermission(dP).
Handle(ms.DeleteMachineScript)
})
2023-01-14 16:29:52 +08:00
runLog := req.NewLogInfo("机器-执行脚本").WithSave(true)
rP := req.NewPermission("machine:script:run")
// 运行脚本
machines.GET(":machineId/scripts/:scriptId/run", func(c *gin.Context) {
2023-01-14 16:29:52 +08:00
req.NewCtxWithGin(c).WithLog(runLog).
2021-06-09 16:58:57 +08:00
WithRequiredPermission(rP).
Handle(ms.RunMachineScript)
})
}
}