From 69d780d5576400e44213b9ee7efa4879ec5d4fdb Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Thu, 18 Jan 2018 09:55:53 -0800 Subject: [PATCH] DNS label validation --- parse/builder/builder.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/parse/builder/builder.go b/parse/builder/builder.go index 97e6b3b0b..3d5070c86 100644 --- a/parse/builder/builder.go +++ b/parse/builder/builder.go @@ -8,6 +8,7 @@ import ( "github.com/rancher/norman/types" "github.com/rancher/norman/types/convert" "github.com/rancher/norman/types/definition" + "k8s.io/apimachinery/pkg/util/validation" ) var ( @@ -258,7 +259,14 @@ func (b *Builder) convert(fieldType string, value interface{}, op Operation) (in case "string": return convert.ToString(value), nil 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": num, err := convert.ToNumber(value) if err == nil {