summaryrefslogtreecommitdiff
path: root/vendor/k8s.io/apimachinery/pkg/util/validation/validation.go
diff options
context:
space:
mode:
authorTomSweeneyRedHat <tsweeney@redhat.com>2020-01-14 14:46:46 -0500
committerTomSweeneyRedHat <tsweeney@redhat.com>2020-01-14 14:46:46 -0500
commitf5bda9994d5e6cb1ee42ade5e7786059feedf633 (patch)
tree4473a0c3b4615ee58165f06ccf57a1bfe4298fe9 /vendor/k8s.io/apimachinery/pkg/util/validation/validation.go
parent564bd693cae4e8a870be7a7860ef673e793f6358 (diff)
downloadpodman-f5bda9994d5e6cb1ee42ade5e7786059feedf633.tar.gz
podman-f5bda9994d5e6cb1ee42ade5e7786059feedf633.tar.bz2
podman-f5bda9994d5e6cb1ee42ade5e7786059feedf633.zip
Bump to Buildah v1.13.1
Signed-off-by: TomSweeneyRedHat <tsweeney@redhat.com>
Diffstat (limited to 'vendor/k8s.io/apimachinery/pkg/util/validation/validation.go')
-rw-r--r--vendor/k8s.io/apimachinery/pkg/util/validation/validation.go46
1 files changed, 45 insertions, 1 deletions
diff --git a/vendor/k8s.io/apimachinery/pkg/util/validation/validation.go b/vendor/k8s.io/apimachinery/pkg/util/validation/validation.go
index 2dd99992d..8e1907c2a 100644
--- a/vendor/k8s.io/apimachinery/pkg/util/validation/validation.go
+++ b/vendor/k8s.io/apimachinery/pkg/util/validation/validation.go
@@ -70,7 +70,11 @@ func IsQualifiedName(value string) []string {
return errs
}
-// IsFullyQualifiedName checks if the name is fully qualified.
+// IsFullyQualifiedName checks if the name is fully qualified. This is similar
+// to IsFullyQualifiedDomainName but requires a minimum of 3 segments instead of
+// 2 and does not accept a trailing . as valid.
+// TODO: This function is deprecated and preserved until all callers migrate to
+// IsFullyQualifiedDomainName; please don't add new callers.
func IsFullyQualifiedName(fldPath *field.Path, name string) field.ErrorList {
var allErrors field.ErrorList
if len(name) == 0 {
@@ -85,6 +89,26 @@ func IsFullyQualifiedName(fldPath *field.Path, name string) field.ErrorList {
return allErrors
}
+// IsFullyQualifiedDomainName checks if the domain name is fully qualified. This
+// is similar to IsFullyQualifiedName but only requires a minimum of 2 segments
+// instead of 3 and accepts a trailing . as valid.
+func IsFullyQualifiedDomainName(fldPath *field.Path, name string) field.ErrorList {
+ var allErrors field.ErrorList
+ if len(name) == 0 {
+ return append(allErrors, field.Required(fldPath, ""))
+ }
+ if strings.HasSuffix(name, ".") {
+ name = name[:len(name)-1]
+ }
+ if errs := IsDNS1123Subdomain(name); len(errs) > 0 {
+ return append(allErrors, field.Invalid(fldPath, name, strings.Join(errs, ",")))
+ }
+ if len(strings.Split(name, ".")) < 2 {
+ return append(allErrors, field.Invalid(fldPath, name, "should be a domain with at least two segments separated by dots"))
+ }
+ return allErrors
+}
+
const labelValueFmt string = "(" + qualifiedNameFmt + ")?"
const labelValueErrMsg string = "a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character"
@@ -285,6 +309,26 @@ func IsValidIP(value string) []string {
return nil
}
+// IsValidIPv4Address tests that the argument is a valid IPv4 address.
+func IsValidIPv4Address(fldPath *field.Path, value string) field.ErrorList {
+ var allErrors field.ErrorList
+ ip := net.ParseIP(value)
+ if ip == nil || ip.To4() == nil {
+ allErrors = append(allErrors, field.Invalid(fldPath, value, "must be a valid IPv4 address"))
+ }
+ return allErrors
+}
+
+// IsValidIPv6Address tests that the argument is a valid IPv6 address.
+func IsValidIPv6Address(fldPath *field.Path, value string) field.ErrorList {
+ var allErrors field.ErrorList
+ ip := net.ParseIP(value)
+ if ip == nil || ip.To4() != nil {
+ allErrors = append(allErrors, field.Invalid(fldPath, value, "must be a valid IPv6 address"))
+ }
+ return allErrors
+}
+
const percentFmt string = "[0-9]+%"
const percentErrMsg string = "a valid percent string must be a numeric string followed by an ending '%'"