mirror of
https://github.com/rancher/norman.git
synced 2025-09-02 15:54:32 +00:00
DnsLabelRestricted type to validate against RFC 1035
k8s uses restricted format for services dnsLabelRestricted: dns1035LabelFmt string = "[a-z]([-a-z0-9]*[a-z0-9])?" dnsLabel:dns1123LabelFmt string = "[a-z0-9]([-a-z0-9]*[a-z0-9])?"
This commit is contained in:
committed by
Darren Shepherd
parent
df1aea6651
commit
e03c72e855
@@ -78,6 +78,8 @@ func getTypeString(nullable bool, typeName string, schema *types.Schema, schemas
|
|||||||
return "intstr.IntOrString"
|
return "intstr.IntOrString"
|
||||||
case "dnsLabel":
|
case "dnsLabel":
|
||||||
return "string"
|
return "string"
|
||||||
|
case "dnsLabelRestricted":
|
||||||
|
return "string"
|
||||||
case "hostname":
|
case "hostname":
|
||||||
return "string"
|
return "string"
|
||||||
default:
|
default:
|
||||||
|
@@ -272,6 +272,18 @@ func (b *Builder) convert(fieldType string, value interface{}, op Operation) (in
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return str, nil
|
return str, nil
|
||||||
|
case "dnsLabelRestricted":
|
||||||
|
str := convert.ToString(value)
|
||||||
|
if str == "" {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
if op == Create || op == Update {
|
||||||
|
if errs := validation.IsDNS1035Label(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":
|
case "hostname":
|
||||||
str := convert.ToString(value)
|
str := convert.ToString(value)
|
||||||
if str == "" {
|
if str == "" {
|
||||||
|
Reference in New Issue
Block a user