From 7b57fa64000460271d7bb43b56bc41a77ed84891 Mon Sep 17 00:00:00 2001 From: Denis Gukov Date: Wed, 20 Sep 2023 20:38:29 +0200 Subject: [PATCH] feat(config): print more info about validation --- util/config.go | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/util/config.go b/util/config.go index c78709b52..0cf9d7875 100644 --- a/util/config.go +++ b/util/config.go @@ -394,23 +394,32 @@ func validate(value interface{}) error { continue } - var value string + var strVal string if fieldType.Type.Kind() == reflect.Int { - value = strconv.FormatInt(fieldValue.Int(), 10) + strVal = strconv.FormatInt(fieldValue.Int(), 10) } else if fieldType.Type.Kind() == reflect.Uint { - value = strconv.FormatUint(fieldValue.Uint(), 10) + strVal = strconv.FormatUint(fieldValue.Uint(), 10) } else { - value = fieldValue.String() + strVal = fieldValue.String() } - match, _ := regexp.MatchString(rule, value) - if !match { - return fmt.Errorf( - "value of field '%v' is not valid! (Must match regex: '%v')", - fieldType.Name, rule, - ) + match, _ := regexp.MatchString(rule, strVal) + + if match { + continue + } + + fieldName := strings.ToLower(fieldType.Name) + + if strings.Contains(fieldName, "password") || strings.Contains(fieldName, "secret") || strings.Contains(fieldName, "key") { + strVal = "***" } + + return fmt.Errorf( + "value of field '%v' is not valid: %v (Must match regex: '%v')", + fieldType.Name, strVal, rule, + ) } return nil