aboutsummaryrefslogtreecommitdiff
path: root/vendor/k8s.io/apimachinery/pkg/util/validation/validation.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-05-08 12:59:42 +0200
committerGitHub <noreply@github.com>2020-05-08 12:59:42 +0200
commit4b300a12cedabff3c57ee657afac0696cefaae0a (patch)
tree61c5fceec50e88338038415fa1375371bef2dca4 /vendor/k8s.io/apimachinery/pkg/util/validation/validation.go
parent70e7fc670be13d3877e65e160456c312e23a5806 (diff)
parent2f0bc5ff1cde9afb595868b92dd123478af9ef74 (diff)
downloadpodman-4b300a12cedabff3c57ee657afac0696cefaae0a.tar.gz
podman-4b300a12cedabff3c57ee657afac0696cefaae0a.tar.bz2
podman-4b300a12cedabff3c57ee657afac0696cefaae0a.zip
Merge pull request #6086 from containers/dependabot/go_modules/k8s.io/api-0.18.2
Bump k8s.io/api from 0.17.4 to 0.18.2
Diffstat (limited to 'vendor/k8s.io/apimachinery/pkg/util/validation/validation.go')
-rw-r--r--vendor/k8s.io/apimachinery/pkg/util/validation/validation.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/vendor/k8s.io/apimachinery/pkg/util/validation/validation.go b/vendor/k8s.io/apimachinery/pkg/util/validation/validation.go
index 8e1907c2a..915231f2e 100644
--- a/vendor/k8s.io/apimachinery/pkg/util/validation/validation.go
+++ b/vendor/k8s.io/apimachinery/pkg/util/validation/validation.go
@@ -109,6 +109,44 @@ func IsFullyQualifiedDomainName(fldPath *field.Path, name string) field.ErrorLis
return allErrors
}
+// Allowed characters in an HTTP Path as defined by RFC 3986. A HTTP path may
+// contain:
+// * unreserved characters (alphanumeric, '-', '.', '_', '~')
+// * percent-encoded octets
+// * sub-delims ("!", "$", "&", "'", "(", ")", "*", "+", ",", ";", "=")
+// * a colon character (":")
+const httpPathFmt string = `[A-Za-z0-9/\-._~%!$&'()*+,;=:]+`
+
+var httpPathRegexp = regexp.MustCompile("^" + httpPathFmt + "$")
+
+// IsDomainPrefixedPath checks if the given string is a domain-prefixed path
+// (e.g. acme.io/foo). All characters before the first "/" must be a valid
+// subdomain as defined by RFC 1123. All characters trailing the first "/" must
+// be valid HTTP Path characters as defined by RFC 3986.
+func IsDomainPrefixedPath(fldPath *field.Path, dpPath string) field.ErrorList {
+ var allErrs field.ErrorList
+ if len(dpPath) == 0 {
+ return append(allErrs, field.Required(fldPath, ""))
+ }
+
+ segments := strings.SplitN(dpPath, "/", 2)
+ if len(segments) != 2 || len(segments[0]) == 0 || len(segments[1]) == 0 {
+ return append(allErrs, field.Invalid(fldPath, dpPath, "must be a domain-prefixed path (such as \"acme.io/foo\")"))
+ }
+
+ host := segments[0]
+ for _, err := range IsDNS1123Subdomain(host) {
+ allErrs = append(allErrs, field.Invalid(fldPath, host, err))
+ }
+
+ path := segments[1]
+ if !httpPathRegexp.MatchString(path) {
+ return append(allErrs, field.Invalid(fldPath, path, RegexError("Invalid path", httpPathFmt)))
+ }
+
+ return allErrs
+}
+
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"