From beefa0cbccbf485d1de66fb521577b863b75fae2 Mon Sep 17 00:00:00 2001 From: ish Date: Mon, 30 Sep 2024 00:29:38 +0900 Subject: [PATCH] server: Limit max connection info length to 200 --- server/pkg/api/rest/controller/connectionInfo.go | 12 ++++++++++++ server/pkg/api/rest/controller/sourceGroup.go | 5 +++++ server/pkg/api/rest/model/connectionInfo.go | 2 ++ 3 files changed, 19 insertions(+) diff --git a/server/pkg/api/rest/controller/connectionInfo.go b/server/pkg/api/rest/controller/connectionInfo.go index 84e24c6..6f6aa86 100644 --- a/server/pkg/api/rest/controller/connectionInfo.go +++ b/server/pkg/api/rest/controller/connectionInfo.go @@ -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()) diff --git a/server/pkg/api/rest/controller/sourceGroup.go b/server/pkg/api/rest/controller/sourceGroup.go index e71764b..c4af510 100644 --- a/server/pkg/api/rest/controller/sourceGroup.go +++ b/server/pkg/api/rest/controller/sourceGroup.go @@ -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, diff --git a/server/pkg/api/rest/model/connectionInfo.go b/server/pkg/api/rest/model/connectionInfo.go index 739648d..1f2c875 100644 --- a/server/pkg/api/rest/model/connectionInfo.go +++ b/server/pkg/api/rest/model/connectionInfo.go @@ -1,5 +1,7 @@ package model +const ConnectionInfoMaxLength = 200 + const ( ConnectionInfoStatusSuccess = "success" ConnectionInfoStatusFailed = "failed"