1
0
mirror of https://github.com/rancher/norman.git synced 2025-09-18 08:14:56 +00:00

Add hostname tag and fix dnsLabel validation issue

This commit is contained in:
zionwu
2018-05-18 14:43:44 +08:00
committed by Denise
parent 6a363d8e93
commit 79b91ea33c
3 changed files with 16 additions and 0 deletions

View File

@@ -261,6 +261,18 @@ func (b *Builder) convert(fieldType string, value interface{}, op Operation) (in
case "string":
return convert.ToString(value), nil
case "dnsLabel":
str := convert.ToString(value)
if str == "" {
return "", nil
}
if op == Create || op == Update {
if errs := validation.IsDNS1123Label(str); len(errs) != 0 {
return value, httperror.NewAPIError(httperror.InvalidFormat, fmt.Sprintf("invalid value %s: %s", value,
strings.Join(errs, ",")))
}
}
return str, nil
case "hostname":
str := convert.ToString(value)
if str == "" {
return "", nil