Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
so-operation-api
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
smart-operation
so-operation-api
Commits
1097a976
Commit
1097a976
authored
Jun 27, 2023
by
陈子龙
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
主机管理 fix
parent
8a8a85aa
Changes
12
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
203 additions
and
282 deletions
+203
-282
go.mod
go.mod
+2
-0
go.sum
go.sum
+5
-0
src/bean/vo/request/doc_lib.go
src/bean/vo/request/doc_lib.go
+1
-0
src/bean/vo/request/host_manage.go
src/bean/vo/request/host_manage.go
+13
-11
src/bean/vo/request/task_manage.go
src/bean/vo/request/task_manage.go
+4
-4
src/controller/doc_lib.go
src/controller/doc_lib.go
+0
-99
src/controller/host_manage.go
src/controller/host_manage.go
+118
-38
src/pkg/beagle/resp/code.go
src/pkg/beagle/resp/code.go
+5
-0
src/router/router.go
src/router/router.go
+1
-10
src/service/doc_lib.go
src/service/doc_lib.go
+2
-3
src/service/host_manage.go
src/service/host_manage.go
+42
-108
src/service/task_manage.go
src/service/task_manage.go
+10
-9
No files found.
go.mod
View file @
1097a976
...
@@ -3,6 +3,7 @@ module gitlab.wodcloud.com/smart-operation/so-operation-api
...
@@ -3,6 +3,7 @@ module gitlab.wodcloud.com/smart-operation/so-operation-api
go 1.19
go 1.19
require (
require (
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
...
@@ -45,6 +46,7 @@ require (
...
@@ -45,6 +46,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
...
...
go.sum
View file @
1097a976
...
@@ -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/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
...
@@ -306,6 +308,8 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN
...
@@ -306,6 +308,8 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
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/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=
...
@@ -409,6 +413,7 @@ github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoH
...
@@ -409,6 +413,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=
...
...
src/bean/vo/request/doc_lib.go
0 → 100644
View file @
1097a976
package
request
src/bean/vo/request/host_manage.go
View file @
1097a976
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
Host
Name
string
`json:"hostName"`
// 主机分组名称
Host
Type
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
}
}
...
...
src/bean/vo/request/task_manage.go
View file @
1097a976
...
@@ -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
}
}
...
...
src/controller/doc_lib.go
View file @
1097a976
...
@@ -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))
//}
src/controller/host_manage.go
View file @
1097a976
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,28 +12,90 @@ import (
...
@@ -10,28 +12,90 @@ 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
)
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
)
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
WithError
(
err
),
nil
)
return
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
return
}
}
if
len
(
req
.
H
ostManageList
)
>
5
{
if
len
(
h
ostManageList
)
>
5
{
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
WithError
(
errors
.
New
(
"主机分组数量超过5条"
)),
nil
)
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
WithError
(
errors
.
New
(
"主机分组数量超过5条"
)),
nil
)
return
return
}
}
for
_
,
v
:=
range
req
.
H
ostManageList
{
for
_
,
v
:=
range
h
ostManageList
{
if
v
.
Ip
==
""
||
v
.
UserName
==
""
{
if
v
.
Ip
==
""
||
v
.
UserName
==
""
{
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
WithError
(
errors
.
New
(
"ip或用户名为空"
)),
nil
)
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
WithError
(
errors
.
New
(
"ip或用户名为空"
)),
nil
)
return
return
...
@@ -41,10 +105,9 @@ func AddHostManage(c *gin.Context) {
...
@@ -41,10 +105,9 @@ func AddHostManage(c *gin.Context) {
return
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,26 +117,44 @@ func AddHostManage(c *gin.Context) {
...
@@ -54,26 +117,44 @@ 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
.
HostName
==
""
||
req
.
Id
==
0
{
if
req
.
HostType
==
0
{
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
WithError
(
errors
.
New
(
"主机分组ID或名称为空"
)),
nil
)
err
=
json
.
Unmarshal
([]
byte
(
req
.
HostManageList
),
&
hostManageList
)
if
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
WithError
(
err
),
nil
)
return
return
}
}
}
else
{
if
req
.
HostFileUrl
==
""
{
if
req
.
HostFileUrl
==
""
{
if
len
(
req
.
HostManageList
)
==
0
{
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
len
(
hostManageList
)
==
0
{
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
WithError
(
errors
.
New
(
"主机分组数量为0"
)),
nil
)
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
WithError
(
errors
.
New
(
"主机分组数量为0"
)),
nil
)
return
return
}
}
if
len
(
req
.
H
ostManageList
)
>
5
{
if
len
(
h
ostManageList
)
>
5
{
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
WithError
(
errors
.
New
(
"主机分组数量超过5条"
)),
nil
)
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
WithError
(
errors
.
New
(
"主机分组数量超过5条"
)),
nil
)
return
return
}
}
for
_
,
v
:=
range
req
.
H
ostManageList
{
for
_
,
v
:=
range
h
ostManageList
{
if
v
.
Ip
==
""
||
v
.
UserName
==
""
{
if
v
.
Ip
==
""
||
v
.
UserName
==
""
{
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
WithError
(
errors
.
New
(
"ip或用户名为空"
)),
nil
)
SendJsonResponse
(
c
,
resp
.
InvalidParam
.
WithError
(
errors
.
New
(
"ip或用户名为空"
)),
nil
)
return
return
...
@@ -83,10 +164,9 @@ func EditHostManage(c *gin.Context) {
...
@@ -83,10 +164,9 @@ func EditHostManage(c *gin.Context) {
return
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
...
...
src/pkg/beagle/resp/code.go
View file @
1097a976
...
@@ -28,4 +28,9 @@ var (
...
@@ -28,4 +28,9 @@ var (
EsConnectError
=
Resp
{
Code
:
5010009
,
Msg
:
"es连接失败"
}
EsConnectError
=
Resp
{
Code
:
5010009
,
Msg
:
"es连接失败"
}
AddSheetError
=
Resp
{
Code
:
5010010
,
Msg
:
"新建sheet失败"
}
AddSheetError
=
Resp
{
Code
:
5010010
,
Msg
:
"新建sheet失败"
}
UnableAccountLock
=
Resp
{
Code
:
5010011
,
Msg
:
"暂无账号锁定"
}
UnableAccountLock
=
Resp
{
Code
:
5010011
,
Msg
:
"暂无账号锁定"
}
// 文件上传
UploadFileError
=
Resp
{
Code
:
6000001
,
Msg
:
"文件上传失败"
}
GetFileStreamError
=
Resp
{
Code
:
6000002
,
Msg
:
"获取文件流失败"
}
ReadFileError
=
Resp
{
Code
:
6000003
,
Msg
:
"读取文件失败"
}
)
)
src/router/router.go
View file @
1097a976
...
@@ -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
)
...
...
src/service/doc_lib.go
View file @
1097a976
...
@@ -13,7 +13,7 @@ import (
...
@@ -13,7 +13,7 @@ import (
"path"
"path"
)
)
var
maxFileByte
int64
=
104857600
//10
0M
var
maxFileByte
int64
=
20971520
//2
0M
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
_f
ile"
)
uploadFile
,
err
=
c
.
FormFile
(
"upload
F
ile"
)
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
}
}
src/service/host_manage.go
View file @
1097a976
...
@@ -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,33 +54,7 @@ func (h *HostManageSvc) AddHostManage(req request.AddHostManageReq) (err error)
...
@@ -54,33 +54,7 @@ func (h *HostManageSvc) AddHostManage(req request.AddHostManageReq) (err error)
session
.
Rollback
()
session
.
Rollback
()
return
return
}
}
if
req
.
HostFileUrl
==
""
{
//新增主机分组列表
//新增主机分组列表
for
_
,
v
:=
range
req
.
HostManageList
{
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
,
}
_
,
err
=
session
.
Table
(
"host_manage_list"
)
.
Insert
(
&
hostManageList
)
if
err
!=
nil
{
err
=
resp
.
DbInsertError
.
WithError
(
err
)
session
.
Rollback
()
return
}
}
}
else
{
//读取并解析文件内容--czl
var
hostManageLists
[]
entity
.
HostManageList
//新增主机分组列表--文件形式
for
_
,
v
:=
range
hostManageLists
{
for
_
,
v
:=
range
hostManageLists
{
port
:=
"22"
port
:=
"22"
if
v
.
Port
!=
""
{
if
v
.
Port
!=
""
{
...
@@ -102,14 +76,13 @@ func (h *HostManageSvc) AddHostManage(req request.AddHostManageReq) (err error)
...
@@ -102,14 +76,13 @@ func (h *HostManageSvc) AddHostManage(req request.AddHostManageReq) (err error)
return
return
}
}
}
}
}
session
.
Commit
()
session
.
Commit
()
return
return
}
}
// 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,32 +117,7 @@ func (h *HostManageSvc) EditHostManage(req request.EditHostManageReq) (err error
...
@@ -158,32 +117,7 @@ func (h *HostManageSvc) EditHostManage(req request.EditHostManageReq) (err error
return
return
}
}
if
req
.
HostFileUrl
==
""
{
//新增主机分组列表
//修改主机分组列表
for
_
,
v
:=
range
req
.
HostManageList
{
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
,
}
_
,
err
=
session
.
Table
(
"host_manage_list"
)
.
Insert
(
&
hostManageList
)
if
err
!=
nil
{
err
=
resp
.
DbInsertError
.
WithError
(
err
)
session
.
Rollback
()
return
}
}
}
else
{
//读取并解析文件内容--czl
var
hostManageLists
[]
entity
.
HostManageList
//新增主机分组列表--文件形式
for
_
,
v
:=
range
hostManageLists
{
for
_
,
v
:=
range
hostManageLists
{
port
:=
"22"
port
:=
"22"
if
v
.
Port
!=
""
{
if
v
.
Port
!=
""
{
...
@@ -205,7 +139,7 @@ func (h *HostManageSvc) EditHostManage(req request.EditHostManageReq) (err error
...
@@ -205,7 +139,7 @@ func (h *HostManageSvc) EditHostManage(req request.EditHostManageReq) (err error
return
return
}
}
}
}
}
session
.
Commit
()
session
.
Commit
()
return
return
}
}
...
...
src/service/task_manage.go
View file @
1097a976
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"
...
@@ -23,15 +24,15 @@ func (t *TaskManageSvc) AddTaskManage(req request.AddTaskManageReq) (err error)
...
@@ -23,15 +24,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
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment