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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]