"src/controller/alert_overview.go" did not exist on "90bbdca96c635bf6eeef94c6eb65057adbefb11b"
Commit d75d0acb authored by 陈子龙's avatar 陈子龙

Merge branch 'dev-czl' into dev

# Conflicts:
#	go.mod
#	go.sum
#	src/pkg/beagle/resp/code.go
parents 79150d86 1097a976
...@@ -4,6 +4,7 @@ go 1.19 ...@@ -4,6 +4,7 @@ go 1.19
require ( require (
github.com/Luzifer/go-openssl/v4 v4.1.0 github.com/Luzifer/go-openssl/v4 v4.1.0
github.com/360EntSecGroup-Skylar/excelize v1.4.1
github.com/bytedance/go-tagexpr v2.7.4+incompatible github.com/bytedance/go-tagexpr v2.7.4+incompatible
github.com/gin-gonic/gin v1.9.0 github.com/gin-gonic/gin v1.9.0
github.com/go-playground/locales v0.14.1 github.com/go-playground/locales v0.14.1
...@@ -50,6 +51,7 @@ require ( ...@@ -50,6 +51,7 @@ require (
github.com/minio/sha256-simd v1.0.1 // indirect github.com/minio/sha256-simd v1.0.1 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/nyaruka/phonenumbers v1.1.7 // indirect github.com/nyaruka/phonenumbers v1.1.7 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/rs/xid v1.5.0 // indirect github.com/rs/xid v1.5.0 // indirect
......
...@@ -3,6 +3,8 @@ cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT ...@@ -3,6 +3,8 @@ cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:lSA0F4e9A2NcQSqGqTOXqu2aRi/XEQxDCBwM8yJtE6s= gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:lSA0F4e9A2NcQSqGqTOXqu2aRi/XEQxDCBwM8yJtE6s=
gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a/go.mod h1:EXuID2Zs0pAQhH8yz+DNjUbjppKQzKFAn28TMYPB6IU= gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a/go.mod h1:EXuID2Zs0pAQhH8yz+DNjUbjppKQzKFAn28TMYPB6IU=
gitee.com/travelliu/dm v1.8.11192/go.mod h1:DHTzyhCrM843x9VdKVbZ+GKXGRbKM2sJ4LxihRxShkE= gitee.com/travelliu/dm v1.8.11192/go.mod h1:DHTzyhCrM843x9VdKVbZ+GKXGRbKM2sJ4LxihRxShkE=
github.com/360EntSecGroup-Skylar/excelize v1.4.1 h1:l55mJb6rkkaUzOpSsgEeKYtS6/0gHwBYyfo5Jcjv/Ks=
github.com/360EntSecGroup-Skylar/excelize v1.4.1/go.mod h1:vnax29X2usfl7HHkBrX5EvSCJcmH3dT9luvxzu8iGAE=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
github.com/Luzifer/go-openssl/v4 v4.1.0 h1:8qi3Z6f8Aflwub/Cs4FVSmKUEg/lC8GlODbR2TyZ+nM= github.com/Luzifer/go-openssl/v4 v4.1.0 h1:8qi3Z6f8Aflwub/Cs4FVSmKUEg/lC8GlODbR2TyZ+nM=
...@@ -313,6 +315,8 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G ...@@ -313,6 +315,8 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/mojocn/base64Captcha v1.3.5 h1:Qeilr7Ta6eDtG4S+tQuZ5+hO+QHbiGAJdi4PfoagaA0= github.com/mojocn/base64Captcha v1.3.5 h1:Qeilr7Ta6eDtG4S+tQuZ5+hO+QHbiGAJdi4PfoagaA0=
github.com/mojocn/base64Captcha v1.3.5/go.mod h1:/tTTXn4WTpX9CfrmipqRytCpJ27Uw3G6I7NcP2WwcmY= github.com/mojocn/base64Captcha v1.3.5/go.mod h1:/tTTXn4WTpX9CfrmipqRytCpJ27Uw3G6I7NcP2WwcmY=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg= github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg=
github.com/nats-io/jwt v0.3.2/go.mod h1:/euKqTS1ZD+zzjYrY7pseZrTtWQSjujC7xjPc8wL6eU= github.com/nats-io/jwt v0.3.2/go.mod h1:/euKqTS1ZD+zzjYrY7pseZrTtWQSjujC7xjPc8wL6eU=
...@@ -417,6 +421,7 @@ github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoH ...@@ -417,6 +421,7 @@ github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoH
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.2.3-0.20181224173747-660f15d67dbb/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
......
package request package request
type AddHostManageReq struct { type AddHostManageReq struct {
HostName string `json:"hostName"` // 主机分组名称 HostName string `form:"hostName" binding:"required"` // 主机分组名称
HostFileUrl string `json:"hostFileUrl"` // 主机文件url HostType int `form:"hostType" binding:"oneof=0 1"` //主机上传类型(0列表维护 1文件上传)
HostManageList []HostManageList `json:"hostManageList"` //主机列表 HostFileUrl string `form:"hostFileUrl"` // 主机文件url
//HostFile string `form:"hostFile"` // 主机文件
HostManageList string `form:"hostManageList"` //主机列表
} }
type HostManageList struct { type HostManageList struct {
Ip string `json:"ip"` // ip Ip string `json:"ip"` // ip
Port string `json:"port"` // 端口 Port string `json:"port"` // 端口
VoucherType int `json:"voucherType"` // 凭证类型(0密码验证 密钥验证) VoucherType int `json:"voucherType"` // 凭证类型(0密码验证 1密钥验证)
UserName string `json:"userName"` // 用户名 UserName string `json:"userName"` // 用户名
Password string `json:"password"` // 密码 Password string `json:"password"` // 密码
} }
type EditHostManageReq struct { type EditHostManageReq struct {
Id int `json:"id"` // 主键ID Id int `form:"id" binding:"required"` // 主键ID
HostName string `json:"hostName"` // 主机分组名称 HostType int `form:"hostType" binding:"oneof=0 1"` //主机上传类型(0列表维护 1文件上传)
HostFileUrl string `json:"hostFileUrl"` // 主机文件url HostFileUrl string `form:"hostFileUrl"` // 主机文件url
HostManageList []HostManageList `json:"hostManageList"` //主机列表 HostManageList string `form:"hostManageList"` //主机列表
} }
type DelHostManageReq struct { type DelHostManageReq struct {
...@@ -26,9 +28,9 @@ type DelHostManageReq struct { ...@@ -26,9 +28,9 @@ type DelHostManageReq struct {
} }
type ListHostManageReq struct { type ListHostManageReq struct {
Search string `json:"search" form:"search"` //关键词 Search string `json:"search"` //关键词
CreateDateFrom string `json:"createDateFrom" form:"createDateFrom"` //创建时间从 CreateDateFrom string `json:"createDateFrom"` //创建时间从
CreateDateTo string `json:"createDateTo" form:"createDateTo"` //创建时间至 CreateDateTo string `json:"createDateTo"` //创建时间至
Pagination Pagination
} }
......
...@@ -3,16 +3,16 @@ package request ...@@ -3,16 +3,16 @@ package request
type AddTaskManageReq struct { type AddTaskManageReq struct {
TaskName string `json:"taskName" vd:"len($)>0;msg:'请输入任务名称'"` // 任务名称 TaskName string `json:"taskName" vd:"len($)>0;msg:'请输入任务名称'"` // 任务名称
TaskDesc string `json:"taskDesc"` // 任务描述 TaskDesc string `json:"taskDesc"` // 任务描述
YamlDesc string `json:"yamlDesc"` // yaml文件 YamlDesc string `json:"yamlDesc"` // yaml内容
YamlUrl string `json:"yamlUrl"` // yaml文件地址 YamlUrl string `json:"yamlUrl"` // yaml文件url
HostGroupId int `json:"hostGroupId" vd:"$>0;msg:'请选择主机分组'"` // 主机分组ID HostGroupId int `json:"hostGroupId" vd:"$>0;msg:'请选择主机分组'"` // 主机分组ID
} }
type EditTaskManageReq struct { type EditTaskManageReq struct {
Id int `json:"id" vd:"$>0;msg:'请输入id'"` // 主键ID Id int `json:"id" vd:"$>0;msg:'请输入id'"` // 主键ID
TaskDesc string `json:"taskDesc"` // 任务描述 TaskDesc string `json:"taskDesc"` // 任务描述
YamlDesc string `json:"yamlDesc"` // yaml文件 YamlDesc string `json:"yamlDesc"` // yaml内容
YamlUrl string `json:"yamlUrl"` // yaml文件地址 YamlUrl string `json:"yamlUrl"` // yaml文件url
HostGroupId int `json:"hostGroupId" vd:"$>0;msg:'请选择主机分组'"` // 主机分组ID HostGroupId int `json:"hostGroupId" vd:"$>0;msg:'请选择主机分组'"` // 主机分组ID
} }
......
...@@ -16,102 +16,3 @@ func AddFile(c *gin.Context) { ...@@ -16,102 +16,3 @@ func AddFile(c *gin.Context) {
} }
SendJsonResponse(c, resp.OK, doc) SendJsonResponse(c, resp.OK, doc)
} }
//
//func (d *DocLib) Get(c *gin.Context) {
// var req request.DocLibGetReq
// if err := c.ShouldBindUri(&req); err != nil {
// resp.Json(c, resp.InvalidParam.WithTranslate(err))
// return
// }
// user, _ := header.GetUserContext(c)
// svc := new(service.DocLibSvc)
// svc.User = &user
// doc, docUrl, err := svc.Get(c, req)
// if err != nil {
// resp.Json(c, resp.FAIL.WithMsg(err.Error()))
// return
// }
// switch req.Opt {
// case "download":
// //c.Redirect(http.StatusMovedPermanently, docUrl.String())
// docUrlParse, _ := url.Parse(docUrl.String())
// proxy := httputil.ReverseProxy{
// Director: func(req *http.Request) {
// req.Header = c.Request.Header
// req.Host = docUrlParse.Host
// req.URL = docUrlParse
// },
// }
// proxy.ServeHTTP(c.Writer, c.Request)
// case "preview":
// c.Redirect(http.StatusMovedPermanently, docUrl.String())
// case "info":
// resp.Json(c, resp.OK.WithData(doc))
// case "tmp":
// resp.Json(c, resp.OK.WithData(docUrl.String()))
// }
//}
//
//func (d *DocLib) List(c *gin.Context) {
// var req request.DocLibListReq
// if err := c.ShouldBind(&req); err != nil {
// resp.Json(c, resp.InvalidParam.WithTranslate(err))
// return
// }
// user, _ := header.GetUserContext(c)
// svc := new(service.DocLibSvc)
// svc.User = &user
// data, err := svc.List(c, req)
// if err != nil {
// resp.Json(c, resp.FAIL.WithMsg(err.Error()))
// return
// }
// resp.Json(c, resp.OK.WithData(data))
//}
//
//func (d *DocLib) Del(c *gin.Context) {
// var req request.DocLibDelReq
// if err := c.ShouldBind(&req); err != nil {
// resp.Json(c, resp.InvalidParam.WithTranslate(err))
// return
// }
// user, _ := header.GetUserContext(c)
// svc := new(service.DocLibSvc)
// svc.User = &user
// err := svc.Del(c, req)
// if err != nil {
// resp.Json(c, resp.FAIL.WithMsg(err.Error()))
// return
// }
// resp.Json(c, resp.OK)
//}
//
//func (d *DocLib) Exts(c *gin.Context) {
// user, _ := header.GetUserContext(c)
// svc := new(service.DocLibSvc)
// svc.User = &user
// data, err := svc.Exts(c)
// if err != nil {
// resp.Json(c, resp.FAIL.WithMsg(err.Error()))
// return
// }
// resp.Json(c, resp.OK.WithData(data))
//}
//
//func (d *DocLib) Update(c *gin.Context) {
// var req request.DocLibUpdateReq
// if err := c.ShouldBind(&req); err != nil {
// resp.Json(c, resp.InvalidParam.WithTranslate(err))
// return
// }
// user, _ := header.GetUserContext(c)
// svc := new(service.DocLibSvc)
// svc.User = &user
// doc, err := svc.Update(c, req)
// if err != nil {
// resp.Json(c, resp.FAIL.WithMsg(err.Error()))
// return
// }
// resp.Json(c, resp.OK.WithData(doc))
//}
package controller package controller
import ( import (
"encoding/json"
"errors" "errors"
"github.com/360EntSecGroup-Skylar/excelize"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/spf13/cast" "github.com/spf13/cast"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/request" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/request"
...@@ -10,41 +12,102 @@ import ( ...@@ -10,41 +12,102 @@ import (
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/util" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/util"
) )
// ParsingHostFiles 解析主机文件
func ParsingHostFiles(c *gin.Context) (hostManageList []request.HostManageList, err error) {
//获取文件流
metaData, _, err := c.Request.FormFile("hostFile")
if err != nil {
err = resp.GetFileStreamError.WithError(err)
return
}
xlsxData, err := excelize.OpenReader(metaData)
if err != nil {
err = resp.ReadFileError.WithError(err)
return
}
//读取工作簿
rows := xlsxData.GetRows("Sheet1")
for i := 0; i < len(rows); i++ {
//默认跳过第一行
if i < 1 {
continue
}
var voucherType int
if rows[i][2] == "密码验证" {
voucherType = 0
} else {
voucherType = 1
}
hostManageList = append(hostManageList, request.HostManageList{
Ip: rows[i][0],
Port: rows[i][1],
VoucherType: voucherType,
UserName: rows[i][3],
Password: rows[i][4],
})
}
return
}
// AddHostManage 新增 // AddHostManage 新增
func AddHostManage(c *gin.Context) { func AddHostManage(c *gin.Context) {
var req request.AddHostManageReq var (
if err := c.ShouldBindJSON(&req); err != nil { req request.AddHostManageReq
err error
)
if err = c.ShouldBind(&req); err != nil {
SendJsonResponse(c, resp.InvalidParam.WithError(err), nil) SendJsonResponse(c, resp.InvalidParam.WithError(err), nil)
return return
} }
hostManageList := make([]request.HostManageList, 0)
if req.HostType == 0 {
err = json.Unmarshal([]byte(req.HostManageList), &hostManageList)
if err != nil {
SendJsonResponse(c, resp.InvalidParam.WithError(err), nil)
return
}
} else {
if req.HostFileUrl == "" {
SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("主机文件url为空")), nil)
return
}
//解析主机文件
hostManageList, err = ParsingHostFiles(c)
if err != nil {
SendJsonResponse(c, resp.ReadFileError.WithError(errors.New("主机文件url为空")), nil)
return
}
}
//参数校验 //参数校验
if req.HostName == "" { if req.HostName == "" {
SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("主机分组名称为空")), nil) SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("主机分组名称为空")), nil)
return return
} }
if req.HostFileUrl == "" { if len(hostManageList) == 0 {
if len(req.HostManageList) == 0 { SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("主机分组数量为0")), nil)
SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("主机分组数量为0")), nil) return
}
if len(hostManageList) > 5 {
SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("主机分组数量超过5条")), nil)
return
}
for _, v := range hostManageList {
if v.Ip == "" || v.UserName == "" {
SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("ip或用户名为空")), nil)
return return
} }
if len(req.HostManageList) > 5 { if v.VoucherType == 0 && v.Password == "" {
SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("主机分组数量超过5条")), nil) SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("密码为空")), nil)
return return
} }
for _, v := range req.HostManageList {
if v.Ip == "" || v.UserName == "" {
SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("ip或用户名为空")), nil)
return
}
if v.VoucherType == 0 && v.Password == "" {
SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("密码为空")), nil)
return
}
}
} }
hostManageSvc := service.HostManageSvc{} hostManageSvc := service.HostManageSvc{}
err := hostManageSvc.AddHostManage(req) err = hostManageSvc.AddHostManage(req, hostManageList)
if err != nil { if err != nil {
SendJsonResponse(c, err, nil) SendJsonResponse(c, err, nil)
return return
...@@ -54,39 +117,56 @@ func AddHostManage(c *gin.Context) { ...@@ -54,39 +117,56 @@ func AddHostManage(c *gin.Context) {
// EditHostManage 编辑 // EditHostManage 编辑
func EditHostManage(c *gin.Context) { func EditHostManage(c *gin.Context) {
var req request.EditHostManageReq var (
if err := c.ShouldBindJSON(&req); err != nil { req request.EditHostManageReq
err error
)
if err := c.ShouldBind(&req); err != nil {
SendJsonResponse(c, resp.InvalidParam.WithError(err), nil) SendJsonResponse(c, resp.InvalidParam.WithError(err), nil)
return return
} }
hostManageList := make([]request.HostManageList, 0)
if req.HostType == 0 {
err = json.Unmarshal([]byte(req.HostManageList), &hostManageList)
if err != nil {
SendJsonResponse(c, resp.InvalidParam.WithError(err), nil)
return
}
} else {
if req.HostFileUrl == "" {
SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("主机文件url为空")), nil)
return
}
//解析主机文件
hostManageList, err = ParsingHostFiles(c)
if err != nil {
SendJsonResponse(c, resp.ReadFileError.WithError(errors.New("主机文件url为空")), nil)
return
}
}
//参数校验 //参数校验
if req.HostName == "" || req.Id == 0 { if len(hostManageList) == 0 {
SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("主机分组ID或名称为空")), nil) SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("主机分组数量为0")), nil)
return return
} }
if req.HostFileUrl == "" { if len(hostManageList) > 5 {
if len(req.HostManageList) == 0 { SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("主机分组数量超过5条")), nil)
SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("主机分组数量为0")), nil) return
}
for _, v := range hostManageList {
if v.Ip == "" || v.UserName == "" {
SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("ip或用户名为空")), nil)
return return
} }
if len(req.HostManageList) > 5 { if v.VoucherType == 0 && v.Password == "" {
SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("主机分组数量超过5条")), nil) SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("密码为空")), nil)
return return
} }
for _, v := range req.HostManageList {
if v.Ip == "" || v.UserName == "" {
SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("ip或用户名为空")), nil)
return
}
if v.VoucherType == 0 && v.Password == "" {
SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("密码为空")), nil)
return
}
}
} }
hostManageSvc := service.HostManageSvc{} hostManageSvc := service.HostManageSvc{}
err := hostManageSvc.EditHostManage(req) err = hostManageSvc.EditHostManage(req, hostManageList)
if err != nil { if err != nil {
SendJsonResponse(c, err, nil) SendJsonResponse(c, err, nil)
return return
......
...@@ -30,4 +30,9 @@ var ( ...@@ -30,4 +30,9 @@ var (
UnableAccountLock = Resp{Code: 5010011, Msg: "暂无账号锁定"} UnableAccountLock = Resp{Code: 5010011, Msg: "暂无账号锁定"}
CmdExecError = Resp{Code: 5010012, Msg: "执行shell命令失败"} CmdExecError = Resp{Code: 5010012, Msg: "执行shell命令失败"}
FileExecError = Resp{Code: 5010013, Msg: "文件执行失败"} FileExecError = Resp{Code: 5010013, Msg: "文件执行失败"}
// 文件上传
UploadFileError = Resp{Code: 6000001, Msg: "文件上传失败"}
GetFileStreamError = Resp{Code: 6000002, Msg: "获取文件流失败"}
ReadFileError = Resp{Code: 6000003, Msg: "读取文件失败"}
) )
...@@ -28,16 +28,7 @@ func Load(r *gin.Engine, middleware ...gin.HandlerFunc) { ...@@ -28,16 +28,7 @@ func Load(r *gin.Engine, middleware ...gin.HandlerFunc) {
base.GET("/example/list", controller.GetExampleList) // 示例获取列表 base.GET("/example/list", controller.GetExampleList) // 示例获取列表
} }
//文档库 base.POST("addFile", controller.AddFile) //文件上传
docLib := base.Group("doc_lib")
{
docLib.POST("addFile", controller.AddFile) //文件上传
//docLib.GET(":id/:opt", docLibController.Get) //预览或下载
//docLib.GET("", docLibController.List) //文档列表
//docLib.DELETE("", docLibController.Del) //删除、移除文档
//docLib.GET("exts", docLibController.Exts) //格式列表
//docLib.PUT("", docLibController.Update) //文档编辑
}
// 初始化自动化运维路由 // 初始化自动化运维路由
InitAutomatedMaintenRouter(r) InitAutomatedMaintenRouter(r)
......
...@@ -13,7 +13,7 @@ import ( ...@@ -13,7 +13,7 @@ import (
"path" "path"
) )
var maxFileByte int64 = 104857600 //100M var maxFileByte int64 = 20971520 //20M
type DocLibSvc struct{} type DocLibSvc struct{}
...@@ -35,7 +35,7 @@ func (d *DocLibSvc) AddFile(c *gin.Context) (fileUrl string, err error) { ...@@ -35,7 +35,7 @@ func (d *DocLibSvc) AddFile(c *gin.Context) (fileUrl string, err error) {
ext string ext string
contentType string contentType string
) )
uploadFile, err = c.FormFile("upload_file") uploadFile, err = c.FormFile("uploadFile")
if err != nil { if err != nil {
err = errors.Wrap(err, "上传的文件不存在") err = errors.Wrap(err, "上传的文件不存在")
return return
...@@ -82,6 +82,5 @@ func (d *DocLibSvc) AddFile(c *gin.Context) (fileUrl string, err error) { ...@@ -82,6 +82,5 @@ func (d *DocLibSvc) AddFile(c *gin.Context) (fileUrl string, err error) {
return return
} }
fileUrl = fmt.Sprintf("https://%s/%s/%s%s", conf.Options.MinioServer, conf.Options.MinioBucket, id, ext) fileUrl = fmt.Sprintf("https://%s/%s/%s%s", conf.Options.MinioServer, conf.Options.MinioBucket, id, ext)
fmt.Printf("https://%s/%s/%s%s", conf.Options.MinioServer, conf.Options.MinioBucket, id, ext)
return return
} }
...@@ -15,7 +15,7 @@ type HostManageSvc struct { ...@@ -15,7 +15,7 @@ type HostManageSvc struct {
} }
// AddHostManage 新增主机 // AddHostManage 新增主机
func (h *HostManageSvc) AddHostManage(req request.AddHostManageReq) (err error) { func (h *HostManageSvc) AddHostManage(req request.AddHostManageReq, hostManageLists []request.HostManageList) (err error) {
db, err := client.GetDbClient() db, err := client.GetDbClient()
if err != nil { if err != nil {
err = resp.DbConnectError.WithError(err) err = resp.DbConnectError.WithError(err)
...@@ -54,53 +54,26 @@ func (h *HostManageSvc) AddHostManage(req request.AddHostManageReq) (err error) ...@@ -54,53 +54,26 @@ func (h *HostManageSvc) AddHostManage(req request.AddHostManageReq) (err error)
session.Rollback() session.Rollback()
return return
} }
//新增主机分组列表
if req.HostFileUrl == "" { for _, v := range hostManageLists {
//新增主机分组列表 port := "22"
for _, v := range req.HostManageList { if v.Port != "" {
port := "22" port = v.Port
if v.Port != "" { }
port = v.Port hostManageList := entity.HostManageList{
} Ip: v.Ip,
hostManageList := entity.HostManageList{ Port: port,
Ip: v.Ip, VoucherType: v.VoucherType,
Port: port, UserName: v.UserName,
VoucherType: v.VoucherType, Password: v.Password,
UserName: v.UserName, HostGroupId: hostManage.Id,
Password: v.Password, HostFileUrl: req.HostFileUrl,
HostGroupId: hostManage.Id,
}
_, err = session.Table("host_manage_list").Insert(&hostManageList)
if err != nil {
err = resp.DbInsertError.WithError(err)
session.Rollback()
return
}
} }
} else { _, err = session.Table("host_manage_list").Insert(&hostManageList)
//读取并解析文件内容--czl if err != nil {
var hostManageLists []entity.HostManageList err = resp.DbInsertError.WithError(err)
//新增主机分组列表--文件形式 session.Rollback()
for _, v := range hostManageLists { return
port := "22"
if v.Port != "" {
port = v.Port
}
hostManageList := entity.HostManageList{
Ip: v.Ip,
Port: port,
VoucherType: v.VoucherType,
UserName: v.UserName,
Password: v.Password,
HostGroupId: hostManage.Id,
HostFileUrl: req.HostFileUrl,
}
_, err = session.Table("host_manage_list").Insert(&hostManageList)
if err != nil {
err = resp.DbInsertError.WithError(err)
session.Rollback()
return
}
} }
} }
...@@ -109,7 +82,7 @@ func (h *HostManageSvc) AddHostManage(req request.AddHostManageReq) (err error) ...@@ -109,7 +82,7 @@ func (h *HostManageSvc) AddHostManage(req request.AddHostManageReq) (err error)
} }
// EditHostManage 编辑 // EditHostManage 编辑
func (h *HostManageSvc) EditHostManage(req request.EditHostManageReq) (err error) { func (h *HostManageSvc) EditHostManage(req request.EditHostManageReq, hostManageLists []request.HostManageList) (err error) {
db, err := client.GetDbClient() db, err := client.GetDbClient()
if err != nil { if err != nil {
err = resp.DbConnectError.WithError(err) err = resp.DbConnectError.WithError(err)
...@@ -121,27 +94,13 @@ func (h *HostManageSvc) EditHostManage(req request.EditHostManageReq) (err error ...@@ -121,27 +94,13 @@ func (h *HostManageSvc) EditHostManage(req request.EditHostManageReq) (err error
defer session.Close() defer session.Close()
session.Begin() session.Begin()
// 校验 主机分组名称 是否重复
has, err := session.Table("host_manage").Where("is_delete = 0 AND id != ? AND host_name = ?", req.Id, req.HostName).Exist()
if has {
err = resp.DbDataCheckError.WithError(errors.New("主机名称重复"))
session.Rollback()
return
}
if err != nil {
err = resp.DbSelectError.WithError(err)
session.Rollback()
return
}
//修改主机分组信息 //修改主机分组信息
hostManage := entity.HostManage{ hostManage := entity.HostManage{
HostName: req.HostName,
UpdateUser: "", UpdateUser: "",
UpdateTime: time.Now(), UpdateTime: time.Now(),
} }
_, err = session.Table("host_manage").Where("is_delete = 0 AND id = ?", req.Id). _, err = session.Table("host_manage").Where("is_delete = 0 AND id = ?", req.Id).
Cols("host_name,update_user,update_time").Update(&hostManage) Cols("update_user,update_time").Update(&hostManage)
if err != nil { if err != nil {
err = resp.DbUpdateError.WithError(err) err = resp.DbUpdateError.WithError(err)
session.Rollback() session.Rollback()
...@@ -158,54 +117,29 @@ func (h *HostManageSvc) EditHostManage(req request.EditHostManageReq) (err error ...@@ -158,54 +117,29 @@ func (h *HostManageSvc) EditHostManage(req request.EditHostManageReq) (err error
return return
} }
if req.HostFileUrl == "" { //新增主机分组列表
//修改主机分组列表 for _, v := range hostManageLists {
for _, v := range req.HostManageList { port := "22"
port := "22" if v.Port != "" {
if v.Port != "" { port = v.Port
port = v.Port
}
hostManageList := entity.HostManageList{
Ip: v.Ip,
Port: port,
VoucherType: v.VoucherType,
UserName: v.UserName,
Password: v.Password,
HostGroupId: hostManage.Id,
}
_, err = session.Table("host_manage_list").Insert(&hostManageList)
if err != nil {
err = resp.DbInsertError.WithError(err)
session.Rollback()
return
}
} }
} else { hostManageList := entity.HostManageList{
//读取并解析文件内容--czl Ip: v.Ip,
var hostManageLists []entity.HostManageList Port: port,
//新增主机分组列表--文件形式 VoucherType: v.VoucherType,
for _, v := range hostManageLists { UserName: v.UserName,
port := "22" Password: v.Password,
if v.Port != "" { HostGroupId: hostManage.Id,
port = v.Port HostFileUrl: req.HostFileUrl,
} }
hostManageList := entity.HostManageList{ _, err = session.Table("host_manage_list").Insert(&hostManageList)
Ip: v.Ip, if err != nil {
Port: port, err = resp.DbInsertError.WithError(err)
VoucherType: v.VoucherType, session.Rollback()
UserName: v.UserName, return
Password: v.Password,
HostGroupId: hostManage.Id,
HostFileUrl: req.HostFileUrl,
}
_, err = session.Table("host_manage_list").Insert(&hostManageList)
if err != nil {
err = resp.DbInsertError.WithError(err)
session.Rollback()
return
}
} }
} }
session.Commit() session.Commit()
return return
} }
......
package service package service
import ( import (
"errors"
"fmt" "fmt"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/entity" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/entity"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/request" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/request"
...@@ -25,15 +26,15 @@ func (t *TaskManageSvc) AddTaskManage(req request.AddTaskManageReq) (err error) ...@@ -25,15 +26,15 @@ func (t *TaskManageSvc) AddTaskManage(req request.AddTaskManageReq) (err error)
} }
// 校验 任务名称 是否重复 // 校验 任务名称 是否重复
//has, err := db.Table("task_manage").Where("is_delete = 0 AND task_name = ?", req.TaskName).Exist() has, err := db.Table("task_manage").Where("is_delete = 0 AND task_name = ?", req.TaskName).Exist()
//if has { if has {
// err = resp.DbDataCheckError.WithError(errors.New("任务名称重复")) err = resp.DbDataCheckError.WithError(errors.New("任务名称重复"))
// return return
//} }
//if err != nil { if err != nil {
// err = resp.DbSelectError.WithError(err) err = resp.DbSelectError.WithError(err)
// return return
//} }
taskManage := entity.TaskManage{ taskManage := entity.TaskManage{
TaskName: req.TaskName, TaskName: req.TaskName,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment