feat: 新增系统操作日志&其他优化

This commit is contained in:
meilin.huang
2022-07-14 11:39:12 +08:00
parent 1c18a01bf6
commit db554ebdc9
38 changed files with 6783 additions and 1388 deletions

View File

@@ -45,10 +45,12 @@ func (d *Db) Save(rc *ctx.ReqCtx) {
form := &form.DbForm{}
ginx.BindJsonAndValid(rc.GinCtx, form)
rc.ReqParam = form
db := new(entity.Db)
utils.Copy(db, form)
// 密码脱敏记录日志
form.Password = "****"
rc.ReqParam = form
db.SetBaseInfo(rc.LoginAccount)
d.DbApp.Save(db)
}
@@ -136,6 +138,8 @@ func (d *Db) ExecSqlFile(rc *ctx.ReqCtx) {
filename := fileheader.Filename
dbId, db := GetIdAndDb(g)
rc.ReqParam = fmt.Sprintf("dbId: %d, db: %s, filename: %s", dbId, db, filename)
go func() {
db := d.DbApp.GetDbInstance(dbId, db)
@@ -192,7 +196,6 @@ func (d *Db) DumpSql(rc *ctx.ReqCtx) {
g.Header("Content-Type", "application/octet-stream")
g.Header("Content-Disposition", "attachment; filename="+filename)
rc.ReqParam = fmt.Sprintf("数据库id: %d -- %s", dbId, db)
writer := g.Writer
writer.WriteString("-- ----------------------------")
writer.WriteString("\n-- 导出平台: mayfly-go")
@@ -258,6 +261,8 @@ func (d *Db) DumpSql(rc *ctx.ReqCtx) {
writer.WriteString("COMMIT;\n")
}
rc.NoRes = true
rc.ReqParam = fmt.Sprintf("dbId: %d, db: %s, tables: %s, dumpType: %s", dbId, db, tablesStr, dumpType)
}
// @router /api/db/:dbId/t-metadata [get]

View File

@@ -57,6 +57,10 @@ func (m *Machine) SaveMachine(rc *ctx.ReqCtx) {
entity := new(entity.Machine)
utils.Copy(entity, machineForm)
// 密码脱敏记录日志
machineForm.Password = "****"
rc.ReqParam = machineForm
entity.SetBaseInfo(rc.LoginAccount)
m.MachineApp.Save(entity)
}

View File

@@ -43,7 +43,8 @@ func (p *Project) GetProjects(rc *ctx.ReqCtx) {
func (p *Project) SaveProject(rc *ctx.ReqCtx) {
project := &entity.Project{}
ginx.BindJsonAndValid(rc.GinCtx, project)
rc.ReqParam = project
rc.ReqParam = fmt.Sprintf("projectId: %d, projectName: %s, remark: %s", project.Id, project.Name, project.Remark)
project.SetBaseInfo(rc.LoginAccount)
p.ProjectApp.SaveProject(project)
@@ -81,7 +82,8 @@ func (p *Project) GetProjectMembers(rc *ctx.ReqCtx) {
func (p *Project) SaveProjectMember(rc *ctx.ReqCtx) {
projectMem := &entity.ProjectMember{}
ginx.BindJsonAndValid(rc.GinCtx, projectMem)
rc.ReqParam = projectMem
rc.ReqParam = fmt.Sprintf("projectId: %d, username: %s", projectMem.ProjectId, projectMem.Username)
// 校验账号并赋值username
account := &sys_entity.Account{}

View File

@@ -36,10 +36,12 @@ func (r *Redis) Save(rc *ctx.ReqCtx) {
form := &form.Redis{}
ginx.BindJsonAndValid(rc.GinCtx, form)
rc.ReqParam = form
redis := new(entity.Redis)
utils.Copy(redis, form)
// 密码脱敏记录日志
form.Password = "****"
rc.ReqParam = form
redis.SetBaseInfo(rc.LoginAccount)
r.RedisApp.Save(redis)
}

View File

@@ -24,14 +24,14 @@ func InitDbRouter(router *gin.RouterGroup) {
rc.Handle(d.Dbs)
})
saveDb := ctx.NewLogInfo("保存数据库信息")
saveDb := ctx.NewLogInfo("保存数据库信息").WithSave(true)
db.POST("", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).
WithLog(saveDb).
Handle(d.Save)
})
deleteDb := ctx.NewLogInfo("删除数据库信息")
deleteDb := ctx.NewLogInfo("删除数据库信息").WithSave(true)
db.DELETE(":dbId", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).
WithLog(deleteDb).
@@ -50,20 +50,23 @@ func InitDbRouter(router *gin.RouterGroup) {
ctx.NewReqCtxWithGin(c).Handle(d.GetCreateTableDdl)
})
// db.GET(":dbId/exec-sql", controllers.SelectData)
execSqlLog := ctx.NewLogInfo("执行Sql语句")
db.POST(":dbId/exec-sql", func(g *gin.Context) {
rc := ctx.NewReqCtxWithGin(g).WithLog(ctx.NewLogInfo("执行Sql语句"))
rc := ctx.NewReqCtxWithGin(g).WithLog(execSqlLog)
rc.Handle(d.ExecSql)
})
execSqlFileLog := ctx.NewLogInfo("执行Sql文件").WithSave(true)
db.POST(":dbId/exec-sql-file", func(g *gin.Context) {
rc := ctx.NewReqCtxWithGin(g).WithLog(ctx.NewLogInfo("执行Sql文件"))
rc.Handle(d.ExecSqlFile)
ctx.NewReqCtxWithGin(g).
WithLog(execSqlFileLog).
Handle(d.ExecSqlFile)
})
dumpLog := ctx.NewLogInfo("导出sql文件").WithSave(true)
db.GET(":dbId/dump", func(g *gin.Context) {
ctx.NewReqCtxWithGin(g).
WithLog(ctx.NewLogInfo("Sql文件dump")).
WithLog(dumpLog).
Handle(d.DumpSql)
})

View File

@@ -29,7 +29,7 @@ func InitMachineRouter(router *gin.RouterGroup) {
})
// 终止进程
killProcessL := ctx.NewLogInfo("终止进程")
killProcessL := ctx.NewLogInfo("终止进程").WithSave(true)
killProcessP := ctx.NewPermission("machine:killprocess")
machines.DELETE(":machineId/process", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).
@@ -38,28 +38,28 @@ func InitMachineRouter(router *gin.RouterGroup) {
Handle(m.KillProcess)
})
saveMachine := ctx.NewLogInfo("保存机器信息")
saveMachine := ctx.NewLogInfo("保存机器信息").WithSave(true)
machines.POST("", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).
WithLog(saveMachine).
Handle(m.SaveMachine)
})
changeStatus := ctx.NewLogInfo("调整机器状态")
changeStatus := ctx.NewLogInfo("调整机器状态").WithSave(true)
machines.PUT(":machineId/:status", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).
WithLog(changeStatus).
Handle(m.ChangeStatus)
})
delMachine := ctx.NewLogInfo("删除机器")
delMachine := ctx.NewLogInfo("删除机器").WithSave(true)
machines.DELETE(":machineId", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).
WithLog(delMachine).
Handle(m.DeleteMachine)
})
closeCli := ctx.NewLogInfo("关闭机器客户端")
closeCli := ctx.NewLogInfo("关闭机器客户端").WithSave(true)
machines.DELETE(":machineId/close-cli", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(closeCli).Handle(m.CloseCli)
})

View File

@@ -24,7 +24,7 @@ func InitMachineFileRouter(router *gin.RouterGroup) {
})
// 新增修改机器文件
addFileConf := ctx.NewLogInfo("新增机器文件配置")
addFileConf := ctx.NewLogInfo("新增机器文件配置").WithSave(true)
afcP := ctx.NewPermission("machine:file:add")
machineFile.POST(":machineId/files", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(addFileConf).
@@ -33,7 +33,7 @@ func InitMachineFileRouter(router *gin.RouterGroup) {
})
// 删除机器文件
delFileConf := ctx.NewLogInfo("删除机器文件配置")
delFileConf := ctx.NewLogInfo("删除机器文件配置").WithSave(true)
dfcP := ctx.NewPermission("machine:file:del")
machineFile.DELETE(":machineId/files/:fileId", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(delFileConf).
@@ -41,7 +41,7 @@ func InitMachineFileRouter(router *gin.RouterGroup) {
Handle(mf.DeleteFile)
})
getContent := ctx.NewLogInfo("读取机器文件内容")
getContent := ctx.NewLogInfo("读取机器文件内容").WithSave(true)
machineFile.GET(":machineId/files/:fileId/read", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(getContent).
Handle(mf.ReadFileContent)
@@ -53,7 +53,7 @@ func InitMachineFileRouter(router *gin.RouterGroup) {
Handle(mf.GetDirEntry)
})
writeFile := ctx.NewLogInfo("写入or下载文件内容")
writeFile := ctx.NewLogInfo("写入or下载文件内容").WithSave(true)
wfP := ctx.NewPermission("machine:file:write")
machineFile.POST(":machineId/files/:fileId/write", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(writeFile).
@@ -61,14 +61,14 @@ func InitMachineFileRouter(router *gin.RouterGroup) {
Handle(mf.WriteFileContent)
})
createFile := ctx.NewLogInfo("创建机器文件or目录")
createFile := ctx.NewLogInfo("创建机器文件or目录").WithSave(true)
machineFile.POST(":machineId/files/:fileId/create-file", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(createFile).
WithRequiredPermission(wfP).
Handle(mf.CreateFile)
})
uploadFile := ctx.NewLogInfo("文件上传")
uploadFile := ctx.NewLogInfo("文件上传").WithSave(true)
ufP := ctx.NewPermission("machine:file:upload")
machineFile.POST(":machineId/files/:fileId/upload", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(uploadFile).
@@ -76,7 +76,7 @@ func InitMachineFileRouter(router *gin.RouterGroup) {
Handle(mf.UploadFile)
})
removeFile := ctx.NewLogInfo("删除文件or文件夹")
removeFile := ctx.NewLogInfo("删除文件or文件夹").WithSave(true)
rfP := ctx.NewPermission("machine:file:rm")
machineFile.DELETE(":machineId/files/:fileId/remove", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(removeFile).

View File

@@ -22,7 +22,7 @@ func InitMachineScriptRouter(router *gin.RouterGroup) {
ctx.NewReqCtxWithGin(c).Handle(ms.MachineScripts)
})
saveMachienScriptLog := ctx.NewLogInfo("保存脚本")
saveMachienScriptLog := ctx.NewLogInfo("保存脚本").WithSave(true)
smsP := ctx.NewPermission("machine:script:save")
// 保存脚本
machines.POST(":machineId/scripts", func(c *gin.Context) {
@@ -31,7 +31,7 @@ func InitMachineScriptRouter(router *gin.RouterGroup) {
Handle(ms.SaveMachineScript)
})
deleteLog := ctx.NewLogInfo("删除脚本")
deleteLog := ctx.NewLogInfo("删除脚本").WithSave(true)
dP := ctx.NewPermission("machine:script:del")
// 保存脚本
machines.DELETE(":machineId/scripts/:scriptId", func(c *gin.Context) {
@@ -40,7 +40,7 @@ func InitMachineScriptRouter(router *gin.RouterGroup) {
Handle(ms.DeleteMachineScript)
})
runLog := ctx.NewLogInfo("执行机器脚本")
runLog := ctx.NewLogInfo("执行机器脚本").WithSave(true)
rP := ctx.NewPermission("machine:script:run")
// 运行脚本
machines.GET(":machineId/scripts/:scriptId/run", func(c *gin.Context) {

View File

@@ -25,7 +25,7 @@ func InitProjectRouter(router *gin.RouterGroup) {
ctx.NewReqCtxWithGin(c).Handle(m.GetProjects)
})
saveProjectLog := ctx.NewLogInfo("保存项目信息")
saveProjectLog := ctx.NewLogInfo("保存项目信息").WithSave(true)
savePP := ctx.NewPermission("project:save")
// 保存项目下的环境信息
project.POST("", func(c *gin.Context) {
@@ -34,7 +34,7 @@ func InitProjectRouter(router *gin.RouterGroup) {
Handle(m.SaveProject)
})
delProjectLog := ctx.NewLogInfo("删除项目信息")
delProjectLog := ctx.NewLogInfo("删除项目信息").WithSave(true)
delPP := ctx.NewPermission("project:del")
// 删除项目
project.DELETE("", func(c *gin.Context) {
@@ -48,7 +48,7 @@ func InitProjectRouter(router *gin.RouterGroup) {
ctx.NewReqCtxWithGin(c).Handle(m.GetProjectEnvs)
})
saveProjectEnvLog := ctx.NewLogInfo("新增项目环境信息")
saveProjectEnvLog := ctx.NewLogInfo("新增项目环境信息").WithSave(true)
savePeP := ctx.NewPermission("project:env:add")
// 保存项目下的环境信息
project.POST("/:projectId/envs", func(c *gin.Context) {
@@ -63,7 +63,7 @@ func InitProjectRouter(router *gin.RouterGroup) {
})
// 保存项目成员
saveProjectMemLog := ctx.NewLogInfo("新增项目成员")
saveProjectMemLog := ctx.NewLogInfo("新增项目成员").WithSave(true)
savePmP := ctx.NewPermission("project:member:add")
project.POST("/:projectId/members", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(saveProjectMemLog).
@@ -72,7 +72,7 @@ func InitProjectRouter(router *gin.RouterGroup) {
})
// 删除项目成员
delProjectMemLog := ctx.NewLogInfo("删除项目成员")
delProjectMemLog := ctx.NewLogInfo("删除项目成员").WithSave(true)
savePmdP := ctx.NewPermission("project:member:del")
project.DELETE("/:projectId/members/:accountId", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(delProjectMemLog).

View File

@@ -21,12 +21,12 @@ func InitRedisRouter(router *gin.RouterGroup) {
ctx.NewReqCtxWithGin(c).Handle(rs.RedisList)
})
save := ctx.NewLogInfo("保存redis信息")
save := ctx.NewLogInfo("保存redis信息").WithSave(true)
redis.POST("", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(save).Handle(rs.Save)
})
delRedis := ctx.NewLogInfo("删除redis信息")
delRedis := ctx.NewLogInfo("删除redis信息").WithSave(true)
redis.DELETE(":id", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(delRedis).Handle(rs.DeleteRedis)
})
@@ -45,8 +45,7 @@ func InitRedisRouter(router *gin.RouterGroup) {
})
// 删除key
deleteKeyL := ctx.NewLogInfo("redis删除key")
// deleteKey := ctx.NewPermission("project:save")
deleteKeyL := ctx.NewLogInfo("redis删除key").WithSave(true)
redis.DELETE(":id/key", func(c *gin.Context) {
ctx.NewReqCtxWithGin(c).WithLog(deleteKeyL).Handle(rs.DeleteKey)
})