forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.go
38 lines (30 loc) · 1004 Bytes
/
helpers.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 api
import (
"fmt"
"strings"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/validation"
)
var NameMayNotBe = []string{".", ".."}
var NameMayNotContain = []string{"/", "%"}
func MinimalNameRequirements(name string, prefix bool) (bool, string) {
for _, illegalName := range NameMayNotBe {
if name == illegalName {
return false, fmt.Sprintf(`name may not be %q`, illegalName)
}
}
for _, illegalContent := range NameMayNotContain {
if strings.Contains(name, illegalContent) {
return false, fmt.Sprintf(`name may not contain %q`, illegalContent)
}
}
return true, ""
}
// GetNameValidationFunc returns a name validation function that includes the standard restrictions we want for all types
func GetNameValidationFunc(nameFunc validation.ValidateNameFunc) validation.ValidateNameFunc {
return func(name string, prefix bool) (bool, string) {
if ok, reason := MinimalNameRequirements(name, prefix); !ok {
return ok, reason
}
return nameFunc(name, prefix)
}
}