You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by "holden-cpu (via GitHub)" <gi...@apache.org> on 2025/08/29 01:39:30 UTC
[PR] support custom validator [servicecomb-service-center]
holden-cpu opened a new pull request, #1519:
URL: https://github.com/apache/servicecomb-service-center/pull/1519
Follow this checklist to help us incorporate your contribution quickly and easily:
- [ ] Make sure there is a [JIRA issue](https://issues.apache.org/jira/browse/SCB) filed for the change (usually before you start working on it). Trivial changes like typos do not require a JIRA issue. Your pull request should address just this issue, without pulling in other changes.
- [ ] Each commit in the pull request should have a meaningful subject line and body.
- [ ] Format the pull request title like `[SCB-XXX] Fixes bug in ApproximateQuantiles`, where you replace `SCB-XXX` with the appropriate JIRA issue.
- [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [ ] Run `go build` `go test` `go fmt` `go vet` to make sure basic checks pass. A more thorough check will be performed on your pull request automatically.
- [ ] If this contribution is large, please file an Apache [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
- [ ] Never comment source code, delete it.
- [ ] UT should has "context, subject, expected result" result as test case name, when you call t.Run().
---
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] support custom validator,add weak password validator 支持自定义校验器,添加弱密码校验 [servicecomb-service-center]
Posted by "humingcheng (via GitHub)" <gi...@apache.org>.
humingcheng merged PR #1519:
URL: https://github.com/apache/servicecomb-service-center/pull/1519
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] support custom validator,add weak password validator [servicecomb-service-center]
Posted by "holden-cpu (via GitHub)" <gi...@apache.org>.
holden-cpu commented on code in PR #1519:
URL: https://github.com/apache/servicecomb-service-center/pull/1519#discussion_r2309291597
##########
server/service/validator/validator.go:
##########
@@ -32,3 +50,77 @@ func baseCheck(v interface{}) error {
}
return nil
}
+
+func customValidate(v interface{}, targetValidators ...string) error {
+ if len(customValidators) == 0 {
+ return nil
+ }
+ for _, validatorName := range targetValidators {
+ validator, exists := customValidators[validatorName]
+ if !exists {
+ log.Info(fmt.Sprintf("validator:%s is not registered,skip", validatorName))
+ continue
+ }
+ validate, err := validator.Validate(v)
+ if err != nil {
+ return err
+ }
+ if !validate {
+ return errors.New(fmt.Sprintf("Validate failed,validator:%s", validatorName))
Review Comment:
不用,遇到校验不通过直接返回即可
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] support custom validator,add weak password validator [servicecomb-service-center]
Posted by "Wanghb1 (via GitHub)" <gi...@apache.org>.
Wanghb1 commented on code in PR #1519:
URL: https://github.com/apache/servicecomb-service-center/pull/1519#discussion_r2309028234
##########
server/service/validator/validator.go:
##########
@@ -32,3 +50,77 @@ func baseCheck(v interface{}) error {
}
return nil
}
+
+func customValidate(v interface{}, targetValidators ...string) error {
+ if len(customValidators) == 0 {
+ return nil
+ }
+ for _, validatorName := range targetValidators {
+ validator, exists := customValidators[validatorName]
+ if !exists {
+ log.Info(fmt.Sprintf("validator:%s is not registered,skip", validatorName))
+ continue
+ }
+ validate, err := validator.Validate(v)
+ if err != nil {
+ return err
+ }
+ if !validate {
+ return errors.New(fmt.Sprintf("Validate failed,validator:%s", validatorName))
Review Comment:
建议多个err一起输出
##########
server/service/validator/validator.go:
##########
@@ -32,3 +50,77 @@ func baseCheck(v interface{}) error {
}
return nil
}
+
+func customValidate(v interface{}, targetValidators ...string) error {
+ if len(customValidators) == 0 {
+ return nil
+ }
+ for _, validatorName := range targetValidators {
+ validator, exists := customValidators[validatorName]
+ if !exists {
+ log.Info(fmt.Sprintf("validator:%s is not registered,skip", validatorName))
+ continue
+ }
+ validate, err := validator.Validate(v)
+ if err != nil {
+ return err
+ }
+ if !validate {
+ return errors.New(fmt.Sprintf("Validate failed,validator:%s", validatorName))
+ }
+ return nil
+ }
+ return nil
+}
+
+func initCustomValidator() {
Review Comment:
initCustomValidator和passwordValidator 放在validate_rbac.go里面
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] support custom validator,add weak password validator [servicecomb-service-center]
Posted by "humingcheng (via GitHub)" <gi...@apache.org>.
humingcheng commented on code in PR #1519:
URL: https://github.com/apache/servicecomb-service-center/pull/1519#discussion_r2309703378
##########
server/service/validator/validator.go:
##########
@@ -32,3 +50,77 @@ func baseCheck(v interface{}) error {
}
return nil
}
+
+func customValidate(v interface{}, targetValidators ...string) error {
+ if len(customValidators) == 0 {
+ return nil
+ }
+ for _, validatorName := range targetValidators {
+ validator, exists := customValidators[validatorName]
+ if !exists {
+ log.Info(fmt.Sprintf("validator:%s is not registered,skip", validatorName))
+ continue
+ }
+ validate, err := validator.Validate(v)
+ if err != nil {
+ return err
+ }
+ if !validate {
+ return errors.New(fmt.Sprintf("Validate failed,validator:%s", validatorName))
+ }
+ return nil
+ }
+ return nil
+}
+
+func initCustomValidator() {
+ weakPasswordPath := os.Getenv(`WEAK_PASSWORD_PATH`)
+ if weakPasswordPath == "" {
+ return
+ }
+ weakPasswords, err := LoadWeakPasswords(weakPasswordPath)
+ if err != nil {
+ log.Error("failed to load weak password", err)
+ return
+ }
+ registerCustomValidator(PasswordCustomValidator, &passwordValidator{weakPasswords: weakPasswords})
Review Comment:
不配置这个文件就会运行失败,限制太死了,要能支持不配置
##########
server/service/validator/validator.go:
##########
@@ -32,3 +50,77 @@ func baseCheck(v interface{}) error {
}
return nil
}
+
+func customValidate(v interface{}, targetValidators ...string) error {
+ if len(customValidators) == 0 {
+ return nil
+ }
+ for _, validatorName := range targetValidators {
+ validator, exists := customValidators[validatorName]
+ if !exists {
+ log.Info(fmt.Sprintf("validator:%s is not registered,skip", validatorName))
+ continue
+ }
+ validate, err := validator.Validate(v)
+ if err != nil {
+ return err
+ }
+ if !validate {
+ return errors.New(fmt.Sprintf("Validate failed,validator:%s", validatorName))
+ }
+ return nil
+ }
+ return nil
+}
+
+func initCustomValidator() {
+ weakPasswordPath := os.Getenv(`WEAK_PASSWORD_PATH`)
Review Comment:
用配置项控制,不要用env,env太隐晦了
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] support custom validator,add weak password validator [servicecomb-service-center]
Posted by "humingcheng (via GitHub)" <gi...@apache.org>.
humingcheng commented on code in PR #1519:
URL: https://github.com/apache/servicecomb-service-center/pull/1519#discussion_r2315077680
##########
server/service/validator/validator.go:
##########
@@ -32,3 +46,32 @@ func baseCheck(v interface{}) error {
}
return nil
}
+
+func customValidate(v interface{}, targetValidators ...string) error {
Review Comment:
这个方法的逻辑:传入多个validator,找到第一个实际存在的validator,并返回该validator的校验结果?把这个逻辑用注释说明一下。
##########
server/service/validator/rbac_validator.go:
##########
@@ -47,13 +57,68 @@ func init() {
changePWDValidator.AddRule("Name", &validate.Rule{Regexp: accountNameRegex})
accountLoginValidator.AddRule("TokenExpirationTime", &validate.Rule{Regexp: &validate.TokenExpirationTimeChecker{}})
+
+ initCustomValidator()
+}
+
+func initPasswordCustomValidator() {
+ weakPasswordPath := filepath.Join(util.GetAppRoot(), "conf", "weakpassord.txt")
+ weakPasswords, err := loadWeakPasswords(weakPasswordPath)
+ if err != nil {
+ log.Error("failed to load weak password", err)
+ return
Review Comment:
弱密码字典初始化失败,整个进程要报错退出。
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org