mirror of
https://github.com/rancher/norman.git
synced 2025-09-13 05:42:37 +00:00
DNS label validation
This commit is contained in:
committed by
Darren Shepherd
parent
c970c36427
commit
69d780d557
@@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/rancher/norman/types"
|
"github.com/rancher/norman/types"
|
||||||
"github.com/rancher/norman/types/convert"
|
"github.com/rancher/norman/types/convert"
|
||||||
"github.com/rancher/norman/types/definition"
|
"github.com/rancher/norman/types/definition"
|
||||||
|
"k8s.io/apimachinery/pkg/util/validation"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -258,7 +259,14 @@ func (b *Builder) convert(fieldType string, value interface{}, op Operation) (in
|
|||||||
case "string":
|
case "string":
|
||||||
return convert.ToString(value), nil
|
return convert.ToString(value), nil
|
||||||
case "dnsLabel":
|
case "dnsLabel":
|
||||||
return convert.ToString(value), nil
|
value := convert.ToString(value)
|
||||||
|
if op == Create || op == Update {
|
||||||
|
if errs := validation.IsDNS1123Subdomain(convert.ToString(value)); len(errs) != 0 {
|
||||||
|
return value, httperror.NewAPIError(httperror.InvalidFormat, fmt.Sprintf("invalid value %s: %s", value,
|
||||||
|
strings.Join(errs, ",")))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return value, nil
|
||||||
case "intOrString":
|
case "intOrString":
|
||||||
num, err := convert.ToNumber(value)
|
num, err := convert.ToNumber(value)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
Reference in New Issue
Block a user