forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validation.go
49 lines (38 loc) · 1.76 KB
/
validation.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package servicebroker
import (
"fmt"
"k8s.io/apimachinery/pkg/util/validation/field"
templateapi "github.com/openshift/origin/pkg/template/apis/template"
templatevalidation "github.com/openshift/origin/pkg/template/apis/template/validation"
"github.com/openshift/origin/pkg/templateservicebroker/openservicebroker/api"
)
// ValidateProvisionRequest ensures that a ProvisionRequest is valid, beyond
// the validation carried out by the service broker framework itself.
func ValidateProvisionRequest(preq *api.ProvisionRequest) field.ErrorList {
var allErrs field.ErrorList
for key := range preq.Parameters {
//TODO - when https://github.com/kubernetes-incubator/service-catalog/pull/939 sufficiently progresses, this if check shoud be removed
if key == templateapi.RequesterUsernameParameterKey {
continue
}
if !templatevalidation.ParameterNameRegexp.MatchString(key) {
allErrs = append(allErrs, field.Invalid(field.NewPath("parameters", key), key, fmt.Sprintf("does not match %v", templatevalidation.ParameterNameRegexp)))
}
}
return allErrs
}
// ValidateBindRequest ensures that a BindRequest is valid, beyond the
// validation carried out by the service broker framework itself.
func ValidateBindRequest(breq *api.BindRequest) field.ErrorList {
var allErrs field.ErrorList
for key := range breq.Parameters {
//TODO - when https://github.com/kubernetes-incubator/service-catalog/pull/939 sufficiently progresses, this if check shoud be removed
if key == templateapi.RequesterUsernameParameterKey {
continue
}
if !templatevalidation.ParameterNameRegexp.MatchString(key) {
allErrs = append(allErrs, field.Invalid(field.NewPath("parameters."+key), key, fmt.Sprintf("does not match %v", templatevalidation.ParameterNameRegexp)))
}
}
return allErrs
}