Skip to content

Commit

Permalink
server: Limit max connection info length to 200
Browse files Browse the repository at this point in the history
  • Loading branch information
ish-hcc committed Sep 29, 2024
1 parent 58bcec2 commit beefa0c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
12 changes: 12 additions & 0 deletions server/pkg/api/rest/controller/connectionInfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,18 @@ func CreateConnectionInfo(c echo.Context) error {
return common.ReturnErrorMsg(c, err.Error())
}

listOption := &model.ConnectionInfo{
SourceGroupID: sourceGroup.ID,
}
connectionInfos, err := dao.ConnectionInfoGetList(listOption, 0, 0)
if err != nil {
return common.ReturnErrorMsg(c, err.Error())
}
if len(*connectionInfos) >= model.ConnectionInfoMaxLength {
return common.ReturnErrorMsg(c, "Maximum number of connection info is exceeded."+
" (Max: "+strconv.Itoa(model.ConnectionInfoMaxLength)+")")
}

connectionInfo, err = doCreateConnectionInfo(connectionInfo)
if err != nil {
return common.ReturnErrorMsg(c, err.Error())
Expand Down
5 changes: 5 additions & 0 deletions server/pkg/api/rest/controller/sourceGroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ func CreateSourceGroup(c echo.Context) error {
return common.ReturnErrorMsg(c, "Please provide the source group's name.")
}

if len(createSourceGroupReq.ConnectionInfo) > model.ConnectionInfoMaxLength {
return common.ReturnErrorMsg(c, "Maximum number of connection info is exceeded."+
" (Max: "+strconv.Itoa(model.ConnectionInfoMaxLength)+")")
}

sourceGroup := &model.SourceGroup{
ID: uuid.New().String(),
Name: createSourceGroupReq.Name,
Expand Down
2 changes: 2 additions & 0 deletions server/pkg/api/rest/model/connectionInfo.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package model

const ConnectionInfoMaxLength = 200

const (
ConnectionInfoStatusSuccess = "success"
ConnectionInfoStatusFailed = "failed"
Expand Down

0 comments on commit beefa0c

Please sign in to comment.