Move IsSecretKey into util/validation

This commit is contained in:
Tim Hockin
2016-04-28 20:34:48 -07:00
parent feea382960
commit 766f44f715
5 changed files with 65 additions and 27 deletions

View File

@@ -247,6 +247,23 @@ func IsHTTPHeaderName(value string) []string {
return nil
}
const configMapKeyFmt = "\\.?" + DNS1123SubdomainFmt
var configMapKeyRegexp = regexp.MustCompile("^" + configMapKeyFmt + "$")
// IsConfigMapKey tests for a string that conforms to the definition of a
// subdomain in DNS (RFC 1123), except that a leading dot is allowed
func IsConfigMapKey(value string) []string {
var errs []string
if len(value) > DNS1123SubdomainMaxLength {
errs = append(errs, MaxLenError(DNS1123SubdomainMaxLength))
}
if !configMapKeyRegexp.MatchString(value) {
errs = append(errs, RegexError(configMapKeyFmt, "key.name"))
}
return errs
}
// MaxLenError returns a string explanation of a "string too long" validation
// failure.
func MaxLenError(length int) string {