Skip to content

Commit

Permalink
Revert "Master local"
Browse files Browse the repository at this point in the history
  • Loading branch information
hLinx committed Jan 8, 2025
1 parent 8e56a7b commit f0374a9
Show file tree
Hide file tree
Showing 200 changed files with 16,736 additions and 191,751 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dbm-services/common/db-config/internal/api/apply_config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package api

import (
"dbm-services/common/go-pubpkg/validate"
"bk-dbconfig/pkg/validate"
)

// ApplyConfigItem TODO
Expand Down
3 changes: 1 addition & 2 deletions dbm-services/common/db-config/internal/api/config_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package api

import (
"bk-dbconfig/pkg/constvar"

"dbm-services/common/go-pubpkg/validate"
"bk-dbconfig/pkg/validate"

"github.com/pkg/errors"
)
Expand Down
6 changes: 2 additions & 4 deletions dbm-services/common/db-config/internal/api/config_plat.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package api

import (
"bk-dbconfig/pkg/validatestruct"

"dbm-services/common/go-pubpkg/validate"
"bk-dbconfig/pkg/validate"
)

// UpsertConfFilePlatReq TODO
Expand Down Expand Up @@ -44,7 +42,7 @@ func (f *UpsertConfFilePlatReq) Validate() error {
if err := validate.GoValidateStruct(*c, true); err != nil {
return err
}
valueTypeSub := validatestruct.ValueTypeDef{ValueType: c.ValueType, ValueTypeSub: c.ValueTypeSub}
valueTypeSub := validate.ValueTypeDef{ValueType: c.ValueType, ValueTypeSub: c.ValueTypeSub}
if err := valueTypeSub.Validate(); err != nil {
return err
}
Expand Down
4 changes: 1 addition & 3 deletions dbm-services/common/db-config/internal/api/dbha.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package api

import (
"dbm-services/common/go-pubpkg/validate"
)
import "bk-dbconfig/pkg/validate"

// BatchGetConfigItemReq TODO
// 批量获取多个对象的某一配置项
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import (
"bk-dbconfig/internal/handler"
"bk-dbconfig/internal/service/simpleconfig"
"bk-dbconfig/pkg/constvar"

"dbm-services/common/go-pubpkg/validate"
"bk-dbconfig/pkg/validate"

"github.com/gin-gonic/gin"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import (
"bk-dbconfig/pkg/constvar"
"bk-dbconfig/pkg/core/logger"
"bk-dbconfig/pkg/util"

"dbm-services/common/go-pubpkg/validate"
"bk-dbconfig/pkg/validate"

"github.com/gin-gonic/gin"
"github.com/pkg/errors"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"bk-dbconfig/pkg/constvar"
"bk-dbconfig/pkg/core/logger"
"bk-dbconfig/pkg/util"
"bk-dbconfig/pkg/validatestruct"
"bk-dbconfig/pkg/validate"

"github.com/pkg/errors"
"github.com/spf13/cast"
Expand Down Expand Up @@ -141,17 +141,17 @@ func CastValueType(confName string, confValue string, f api.BaseConfFileDef, val
if valueType == "" {
return confValue
}
if valueType == validatestruct.DTypeInt {
if valueType == validate.DTypeInt {
return cast.ToInt(confValue)
} else if valueType == validatestruct.DTypeFloat || valueType == validatestruct.DTypeNumber {
} else if valueType == validate.DTypeFloat || valueType == validate.DTypeNumber {
return cast.ToFloat32(confValue)
} else if valueType == validatestruct.DTypeBool {
} else if valueType == validate.DTypeBool {
return cmutil.ToBoolExt(confValue)
} else if valueType == validatestruct.DTypeString {
if valueSubType == validatestruct.DTypeSubList {
} else if valueType == validate.DTypeString {
if valueSubType == validate.DTypeSubList {
newValue := util.SplitAnyRuneTrim(confValue, ",")
return newValue
} else if valueSubType == validatestruct.DTypeSubMap {
} else if valueSubType == validate.DTypeSubMap {
mapI := make(map[string]interface{})
err := json.Unmarshal([]byte(confValue), &mapI)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"bk-dbconfig/internal/pkg/errno"
"bk-dbconfig/internal/repository/model"
"bk-dbconfig/pkg/util"
"bk-dbconfig/pkg/validatestruct"
"bk-dbconfig/pkg/validate"

"github.com/pkg/errors"
"gorm.io/gorm"
Expand Down Expand Up @@ -59,7 +59,7 @@ func CheckConfNameAndValue(c *model.ConfigModel, checkValue bool, valueType, val
}
cn.ValueDefault = c.ConfValue
// 如果不校验 conf_name, 那么 conf_name 可能在 name_def 里没定义,value_type, value_type_sub, value_allowed 都为空
err := validatestruct.ValidateConfValue(cn.ValueDefault, cn.ValueType, cn.ValueTypeSub, cn.ValueAllowed)
err := validate.ValidateConfValue(cn.ValueDefault, cn.ValueType, cn.ValueTypeSub, cn.ValueAllowed)
if err != nil {
errors.WithMessage(err, c.ConfName)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
/*
* TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available.
* Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at https://opensource.org/licenses/MIT
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package validatestruct
package validate

import (
"encoding/json"
Expand Down Expand Up @@ -331,79 +321,70 @@ func ValidateConfValue(confValue, valueType, valueTypeSub, valueAllowed string)
return invalidErr
}
} else if util.StringsHas([]string{DTypeInt, DTypeFloat, DTypeNumber}, valueType) {
return validateValueNumber(valueType, valueTypeSub, confValue, valueAllowed)
} else { // STRING
return validateValueString(valueType, valueTypeSub, confValue, valueAllowed)
}
}

func validateValueNumber(valueType, valueTypeSub, confValue, valueAllowed string) error {
if valueTypeSub == "" {
valueTypeSub = AutoDetectTypeSub(valueAllowed)
if valueTypeSub == "" {
return errors.Errorf("cannot detect value_type_sub for %s", valueAllowed)
}
}
switch valueTypeSub {
case DTypeSubEnum:
return CheckInEnums(confValue, valueAllowed, false)
case DTypeSubRange:
return CheckInRange(confValue, valueAllowed)
default:
var invalidErr = errors.Errorf("invalid value_type_sub %s for %s", valueTypeSub, valueType)
return invalidErr
}
}

func validateValueString(valueType, valueTypeSub, confValue, valueAllowed string) error {
if valueAllowed == "" && !(valueTypeSub == DTypeSubJson || valueTypeSub == DTypeSubMap) {
// JSON,MAP 合法性 不依赖 valueAllowed
return nil
}
switch valueTypeSub {
case DTypeSubEnum:
if err := CheckInEnums(confValue, valueAllowed, false); err != nil {
return err
}
case DTypeSubEnums:
if err := CheckInEnums(confValue, valueAllowed, true); err != nil {
return err
}
case DTypeSubRegex:
if err := CheckInRegex(confValue, valueAllowed); err != nil {
return err
}
case DTypeSubBytes:
if err := CheckInSizeRange(confValue, valueAllowed); err != nil {
return err
}
case DTypeSubDuration:
if err := CheckInDuration(confValue, valueAllowed); err != nil {
return err
valueTypeSub = AutoDetectTypeSub(valueAllowed)
if valueTypeSub == "" {
return errors.Errorf("cannot detect value_type_sub for %s", valueAllowed)
}
}
case DTypeSubJson, DTypeSubMap:
if err := CheckInJson(confValue); err != nil {
return err
switch valueTypeSub {
case DTypeSubEnum:
return CheckInEnums(confValue, valueAllowed, false)
case DTypeSubRange:
return CheckInRange(confValue, valueAllowed)
default:
return invalidErr
}
case DTypeSubGovalidate:
if err := CheckGoValidate(confValue, valueAllowed); err != nil {
return err
} else { // STRING
if valueAllowed == "" && !(valueTypeSub == DTypeSubJson || valueTypeSub == DTypeSubMap) {
// JSON,MAP 合法性 不依赖 valueAllowed
return nil
}
case DTypeSubList:
// 忽略 value_allowed,只用户返回格式化
return nil
case DTypeSubString, "":
if valueAllowed != "" {
// value_allowed !='' and value_type_sub='',要求 conf_value 只能一个值即 value_allowed
if confValue != valueAllowed {
return errors.Errorf("value must equal value_allowed:%s", valueAllowed)
switch valueTypeSub {
case DTypeSubEnum:
if err := CheckInEnums(confValue, valueAllowed, false); err != nil {
return err
}
case DTypeSubEnums:
if err := CheckInEnums(confValue, valueAllowed, true); err != nil {
return err
}
case DTypeSubRegex:
if err := CheckInRegex(confValue, valueAllowed); err != nil {
return err
}
case DTypeSubBytes:
if err := CheckInSizeRange(confValue, valueAllowed); err != nil {
return err
}
case DTypeSubDuration:
if err := CheckInDuration(confValue, valueAllowed); err != nil {
return err
}
case DTypeSubJson, DTypeSubMap:
if err := CheckInJson(confValue); err != nil {
return err
}
case DTypeSubGovalidate:
if err := CheckGoValidate(confValue, valueAllowed); err != nil {
return err
}
case DTypeSubList:
// 忽略 value_allowed,只用户返回格式化
return nil
case DTypeSubString, "":
if valueAllowed != "" {
// value_allowed !='' and value_type_sub='',要求 conf_value 只能一个值即 value_allowed
if confValue != valueAllowed {
return errors.Errorf("value must equal value_allowed:%s", valueAllowed)
}
return nil
}
return nil
default:
return invalidErr
}
return nil
default:
var invalidErr = errors.Errorf("invalid value_type_sub %s for %s", valueTypeSub, valueType)
return invalidErr
}

return nil
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package validatestruct
package validate

import (
"bk-dbconfig/pkg/util"
"log"
"testing"

"bk-dbconfig/pkg/util"

. "github.com/smartystreets/goconvey/convey"
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package validatestruct
package validate

import "regexp"

Expand Down
Loading

0 comments on commit f0374a9

Please sign in to comment.