forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
validation.go
38 lines (29 loc) · 1.28 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
package servicebroker
import (
"fmt"
"k8s.io/apimachinery/pkg/util/validation/field"
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 {
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 {
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
}