Skip to content

Commit

Permalink
DNS label validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Alena Prokharchyk authored and ibuildthecloud committed Jan 20, 2018
1 parent c970c36 commit 69d780d
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion parse/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 69d780d

Please sign in to comment.