检查域名是否存在时同时检查泛域名

This commit is contained in:
刘祥超
2022-09-17 11:38:47 +08:00
parent ee2c253e7d
commit 5f822062da
2 changed files with 36 additions and 5 deletions

View File

@@ -1880,8 +1880,8 @@ func (this *ServerDAO) CheckPortIsUsing(tx *dbs.Tx, clusterId int64, protocolFam
}
// ExistServerNameInCluster 检查ServerName是否已存在
func (this *ServerDAO) ExistServerNameInCluster(tx *dbs.Tx, clusterId int64, serverName string, excludeServerId int64) (bool, error) {
query := this.Query(tx).
func (this *ServerDAO) ExistServerNameInCluster(tx *dbs.Tx, clusterId int64, serverName string, excludeServerId int64, supportWildcard bool) (bool, error) {
var query = this.Query(tx).
Attr("clusterId", clusterId).
Where("(JSON_CONTAINS(serverNames, :jsonQuery1) OR JSON_CONTAINS(serverNames, :jsonQuery2))").
Param("jsonQuery1", maps.Map{"name": serverName}.AsJSON()).
@@ -1890,7 +1890,38 @@ func (this *ServerDAO) ExistServerNameInCluster(tx *dbs.Tx, clusterId int64, ser
query.Neq("id", excludeServerId)
}
query.State(ServerStateEnabled)
return query.Exist()
exists, err := query.Exist()
if err != nil || exists {
return exists, err
}
if supportWildcard {
var countPieces = strings.Count(serverName, ".")
for {
var index = strings.Index(serverName, ".")
if index > 0 {
serverName = serverName[index+1:]
var search = strings.Repeat("*.", countPieces-strings.Count(serverName, ".")) + serverName
var query = this.Query(tx).
Attr("clusterId", clusterId).
Where("(JSON_CONTAINS(serverNames, :jsonQuery1) OR JSON_CONTAINS(serverNames, :jsonQuery2))").
Param("jsonQuery1", maps.Map{"name": search}.AsJSON()).
Param("jsonQuery2", maps.Map{"subNames": search}.AsJSON())
if excludeServerId > 0 {
query.Neq("id", excludeServerId)
}
query.State(ServerStateEnabled)
exists, err = query.Exist()
if err != nil || exists {
return exists, err
}
} else {
break
}
}
}
return false, nil
}
// GenDNSName 生成DNS Name

View File

@@ -1707,9 +1707,9 @@ func (this *ServerService) CheckServerNameDuplicationInNodeCluster(ctx context.C
var tx = this.NullTx()
duplicatedServerNames := []string{}
var duplicatedServerNames = []string{}
for _, serverName := range req.ServerNames {
exist, err := models.SharedServerDAO.ExistServerNameInCluster(tx, req.NodeClusterId, serverName, req.ExcludeServerId)
exist, err := models.SharedServerDAO.ExistServerNameInCluster(tx, req.NodeClusterId, serverName, req.ExcludeServerId, req.SupportWildcard)
if err != nil {
return nil, err
}