|
| 1 | +package v1 |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/1Panel-dev/1Panel/backend/app/api/v1/helper" |
| 5 | + "github.com/1Panel-dev/1Panel/backend/app/dto/request" |
| 6 | + "github.com/1Panel-dev/1Panel/backend/constant" |
| 7 | + "github.com/1Panel-dev/1Panel/backend/global" |
| 8 | + "github.com/gin-gonic/gin" |
| 9 | +) |
| 10 | + |
| 11 | +// @Tags Host tool |
| 12 | +// @Summary Get tool |
| 13 | +// @Description 获取主机工具状态 |
| 14 | +// @Accept json |
| 15 | +// @Param request body request.HostToolReq true "request" |
| 16 | +// @Success 200 |
| 17 | +// @Security ApiKeyAuth |
| 18 | +// @Router /host/tool [post] |
| 19 | +func (b *BaseApi) GetToolStatus(c *gin.Context) { |
| 20 | + var req request.HostToolReq |
| 21 | + if err := c.ShouldBindJSON(&req); err != nil { |
| 22 | + helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) |
| 23 | + return |
| 24 | + } |
| 25 | + if err := global.VALID.Struct(req); err != nil { |
| 26 | + helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) |
| 27 | + return |
| 28 | + } |
| 29 | + |
| 30 | + config, err := hostToolService.GetToolStatus(req) |
| 31 | + if err != nil { |
| 32 | + helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) |
| 33 | + return |
| 34 | + } |
| 35 | + helper.SuccessWithData(c, config) |
| 36 | +} |
| 37 | + |
| 38 | +// @Tags Host tool |
| 39 | +// @Summary Create Host tool Config |
| 40 | +// @Description 创建主机工具配置 |
| 41 | +// @Accept json |
| 42 | +// @Param request body request.HostToolCreate true "request" |
| 43 | +// @Success 200 |
| 44 | +// @Security ApiKeyAuth |
| 45 | +// @Router /host/tool/create [post] |
| 46 | +// @x-panel-log {"bodyKeys":["type"],"paramKeys":[],"BeforeFuntions":[],"formatZH":"创建 [type] 配置","formatEN":"create [type] config"} |
| 47 | +func (b *BaseApi) InitToolConfig(c *gin.Context) { |
| 48 | + var req request.HostToolCreate |
| 49 | + if err := c.ShouldBindJSON(&req); err != nil { |
| 50 | + helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) |
| 51 | + return |
| 52 | + } |
| 53 | + if err := global.VALID.Struct(req); err != nil { |
| 54 | + helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) |
| 55 | + return |
| 56 | + } |
| 57 | + |
| 58 | + if err := hostToolService.CreateToolConfig(req); err != nil { |
| 59 | + helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) |
| 60 | + return |
| 61 | + } |
| 62 | + helper.SuccessWithOutData(c) |
| 63 | +} |
| 64 | + |
| 65 | +// @Tags Host tool |
| 66 | +// @Summary Operate tool |
| 67 | +// @Description 操作主机工具 |
| 68 | +// @Accept json |
| 69 | +// @Param request body request.HostToolReq true "request" |
| 70 | +// @Success 200 |
| 71 | +// @Security ApiKeyAuth |
| 72 | +// @Router /host/tool/operate [post] |
| 73 | +// @x-panel-log {"bodyKeys":["operate","type"],"paramKeys":[],"BeforeFuntions":[],"formatZH":"[operate] [type] ","formatEN":"[operate] [type]"} |
| 74 | +func (b *BaseApi) OperateTool(c *gin.Context) { |
| 75 | + var req request.HostToolReq |
| 76 | + if err := c.ShouldBindJSON(&req); err != nil { |
| 77 | + helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) |
| 78 | + return |
| 79 | + } |
| 80 | + if err := global.VALID.Struct(req); err != nil { |
| 81 | + helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) |
| 82 | + return |
| 83 | + } |
| 84 | + |
| 85 | + err := hostToolService.OperateTool(req) |
| 86 | + if err != nil { |
| 87 | + helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) |
| 88 | + return |
| 89 | + } |
| 90 | + helper.SuccessWithOutData(c) |
| 91 | +} |
| 92 | + |
| 93 | +// @Tags Host tool |
| 94 | +// @Summary Get tool config |
| 95 | +// @Description 操作主机工具配置文件 |
| 96 | +// @Accept json |
| 97 | +// @Param request body request.HostToolConfig true "request" |
| 98 | +// @Success 200 |
| 99 | +// @Security ApiKeyAuth |
| 100 | +// @Router /host/tool/config [post] |
| 101 | +// @x-panel-log {"bodyKeys":["operate"],"paramKeys":[],"BeforeFuntions":[],"formatZH":"[operate] 主机工具配置文件 ","formatEN":"[operate] tool config"} |
| 102 | +func (b *BaseApi) OperateToolConfig(c *gin.Context) { |
| 103 | + var req request.HostToolConfig |
| 104 | + if err := c.ShouldBindJSON(&req); err != nil { |
| 105 | + helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) |
| 106 | + return |
| 107 | + } |
| 108 | + if err := global.VALID.Struct(req); err != nil { |
| 109 | + helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) |
| 110 | + return |
| 111 | + } |
| 112 | + |
| 113 | + config, err := hostToolService.OperateToolConfig(req) |
| 114 | + if err != nil { |
| 115 | + helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) |
| 116 | + return |
| 117 | + } |
| 118 | + helper.SuccessWithData(c, config) |
| 119 | +} |
| 120 | + |
| 121 | +// @Tags Host tool |
| 122 | +// @Summary Get tool |
| 123 | +// @Description 获取主机工具日志 |
| 124 | +// @Accept json |
| 125 | +// @Param request body request.HostToolLogReq true "request" |
| 126 | +// @Success 200 |
| 127 | +// @Security ApiKeyAuth |
| 128 | +// @Router /host/tool/log [post] |
| 129 | +func (b *BaseApi) GetToolLog(c *gin.Context) { |
| 130 | + var req request.HostToolLogReq |
| 131 | + if err := c.ShouldBindJSON(&req); err != nil { |
| 132 | + helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) |
| 133 | + return |
| 134 | + } |
| 135 | + if err := global.VALID.Struct(req); err != nil { |
| 136 | + helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) |
| 137 | + return |
| 138 | + } |
| 139 | + |
| 140 | + logContent, err := hostToolService.GetToolLog(req) |
| 141 | + if err != nil { |
| 142 | + helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) |
| 143 | + return |
| 144 | + } |
| 145 | + helper.SuccessWithData(c, logContent) |
| 146 | +} |
| 147 | + |
| 148 | +// @Tags Host tool |
| 149 | +// @Summary Create Supervisor process |
| 150 | +// @Description 操作守护进程 |
| 151 | +// @Accept json |
| 152 | +// @Param request body request.SupervisorProcessConfig true "request" |
| 153 | +// @Success 200 |
| 154 | +// @Security ApiKeyAuth |
| 155 | +// @Router /host/tool/supervisor/process [post] |
| 156 | +// @x-panel-log {"bodyKeys":["operate"],"paramKeys":[],"BeforeFuntions":[],"formatZH":"[operate] 守护进程 ","formatEN":"[operate] process"} |
| 157 | +func (b *BaseApi) OperateProcess(c *gin.Context) { |
| 158 | + var req request.SupervisorProcessConfig |
| 159 | + if err := c.ShouldBindJSON(&req); err != nil { |
| 160 | + helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) |
| 161 | + return |
| 162 | + } |
| 163 | + if err := global.VALID.Struct(req); err != nil { |
| 164 | + helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) |
| 165 | + return |
| 166 | + } |
| 167 | + |
| 168 | + err := hostToolService.OperateSupervisorProcess(req) |
| 169 | + if err != nil { |
| 170 | + helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) |
| 171 | + return |
| 172 | + } |
| 173 | + helper.SuccessWithOutData(c) |
| 174 | +} |
0 commit comments