mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-09-05 22:25:49 +08:00
feat: 系统操作日志过滤敏感信息
This commit is contained in:
parent
edf2c79990
commit
671b3e853d
3 changed files with 34 additions and 11 deletions
|
@ -6,6 +6,7 @@ import (
|
|||
"github.com/1Panel-dev/1Panel/app/dto"
|
||||
"github.com/1Panel-dev/1Panel/app/model"
|
||||
"github.com/1Panel-dev/1Panel/constant"
|
||||
"github.com/1Panel-dev/1Panel/global"
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
@ -33,14 +34,39 @@ func (u *OperationService) Page(page, size int) (int64, interface{}, error) {
|
|||
if err := copier.Copy(&item, &op); err != nil {
|
||||
return 0, nil, errors.WithMessage(constant.ErrStructTransform, err.Error())
|
||||
}
|
||||
item.Body = filterSensitive(item.Body)
|
||||
var res dto.Response
|
||||
if err := json.Unmarshal([]byte(item.Resp), &res); err == nil {
|
||||
item.Status = res.Code
|
||||
if item.Status != 200 {
|
||||
item.ErrorMessage = res.Msg
|
||||
}
|
||||
if err := json.Unmarshal([]byte(item.Resp), &res); err != nil {
|
||||
global.LOG.Errorf("unmarshal failed, err: %+v", err)
|
||||
dtoOps = append(dtoOps, item)
|
||||
continue
|
||||
}
|
||||
item.Status = res.Code
|
||||
if item.Status != 200 {
|
||||
item.ErrorMessage = res.Msg
|
||||
}
|
||||
dtoOps = append(dtoOps, item)
|
||||
}
|
||||
return total, dtoOps, err
|
||||
}
|
||||
|
||||
func filterSensitive(vars string) string {
|
||||
var Sensitives = []string{"password", "Password"}
|
||||
ops := make(map[string]string)
|
||||
if err := json.Unmarshal([]byte(vars), &ops); err != nil {
|
||||
return vars
|
||||
}
|
||||
for k := range ops {
|
||||
for _, sen := range Sensitives {
|
||||
if k == sen {
|
||||
delete(ops, k)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
backStr, err := json.Marshal(ops)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return string(backStr)
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ func NewIUserService() IUserService {
|
|||
func (u *UserService) Get(name string) (*dto.UserBack, error) {
|
||||
user, err := userRepo.Get(commonRepo.WithByName(name))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, constant.ErrRecordNotFound
|
||||
}
|
||||
var dtoUser dto.UserBack
|
||||
if err := copier.Copy(&dtoUser, &user); err != nil {
|
||||
|
@ -59,7 +59,7 @@ func (u *UserService) Page(search dto.UserPage) (int64, interface{}, error) {
|
|||
func (u *UserService) Register(userDto dto.UserCreate) error {
|
||||
user, _ := userRepo.Get(commonRepo.WithByName(userDto.Name))
|
||||
if user.ID != 0 {
|
||||
return errors.Wrap(constant.ErrRecordExist, "data exist")
|
||||
return constant.ErrRecordExist
|
||||
}
|
||||
if err := copier.Copy(&user, &userDto); err != nil {
|
||||
return errors.WithMessage(constant.ErrStructTransform, err.Error())
|
||||
|
|
|
@ -11,11 +11,8 @@ func Copy(to, from interface{}) error {
|
|||
if err != nil {
|
||||
return errors.Wrap(err, "marshal from data err")
|
||||
}
|
||||
|
||||
err = json.Unmarshal(b, to)
|
||||
if err != nil {
|
||||
if err = json.Unmarshal(b, to); err != nil {
|
||||
return errors.Wrap(err, "unmarshal to data err")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue