forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validation.go
44 lines (38 loc) · 1.4 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
package validation
import (
"strings"
errs "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
kvalidation "github.com/GoogleCloudPlatform/kubernetes/pkg/api/validation"
"github.com/openshift/origin/pkg/user/api"
)
func ValidateUserName(name string, prefix bool) (bool, string) {
if strings.Contains(name, "%") {
return false, `Usernames may not contain "%"`
}
if strings.Contains(name, "/") {
return false, `Usernames may not contain "/"`
}
if name == ".." {
return false, `Usernames may not equal ".."`
}
if name == "." {
return false, `Usernames may not equal "."`
}
return true, ""
}
func ValidateUser(user *api.User) errs.ValidationErrorList {
allErrs := errs.ValidationErrorList{}
allErrs = append(allErrs, kvalidation.ValidateObjectMeta(&user.ObjectMeta, false, ValidateUserName).Prefix("metadata")...)
return allErrs
}
func ValidateIdentity(identity *api.Identity) errs.ValidationErrorList {
allErrs := errs.ValidationErrorList{}
return allErrs
}
func ValidateUserIdentityMapping(mapping *api.UserIdentityMapping) errs.ValidationErrorList {
allErrs := errs.ValidationErrorList{}
allErrs = append(allErrs, kvalidation.ValidateObjectMeta(&mapping.ObjectMeta, false, ValidateUserName).Prefix("metadata")...)
allErrs = append(allErrs, ValidateIdentity(&mapping.Identity).Prefix("identity")...)
allErrs = append(allErrs, ValidateUser(&mapping.User).Prefix("user")...)
return allErrs
}