1
0
mirror of https://github.com/rancher/norman.git synced 2025-09-16 07:09:44 +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

@@ -78,6 +78,8 @@ func getTypeString(nullable bool, typeName string, schema *types.Schema, schemas
return "intstr.IntOrString"
case "dnsLabel":
return "string"
case "hostname":
return "string"
default:
if schema != nil && schemas != nil {
otherSchema := schemas.Schema(&schema.Version, typeName)

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

View File

@@ -101,6 +101,8 @@ func (s *Schemas) setupFilters(schema *Schema) {
mods = []ModifierType{ModifierEQ, ModifierNE, ModifierIn, ModifierNotIn}
case "dnsLabel":
fallthrough
case "hostname":
fallthrough
case "string":
mods = []ModifierType{ModifierEQ, ModifierNE, ModifierIn, ModifierNotIn}
case "int":