Skip to content

Commit

Permalink
Merge validate httptoute (istio#27936)
Browse files Browse the repository at this point in the history
  • Loading branch information
hzxuzhonghu authored Oct 15, 2020
1 parent e926471 commit 19581dd
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 193 deletions.
103 changes: 0 additions & 103 deletions pkg/config/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -1769,109 +1769,6 @@ func validateTCPMatch(match *networking.L4MatchAttributes) (errs error) {
return
}

func validateHTTPRoute(http *networking.HTTPRoute, delegate bool) (errs error) {
if features.EnableVirtualServiceDelegate {
if delegate {
return validateDelegateHTTPRoute(http)
}
if http.Delegate != nil {
return validateRootHTTPRoute(http)
}
}

// check for conflicts
if http.Redirect != nil {
if len(http.Route) > 0 {
errs = appendErrors(errs, errors.New("HTTP route cannot contain both route and redirect"))
}

if http.Fault != nil {
errs = appendErrors(errs, errors.New("HTTP route cannot contain both fault and redirect"))
}

if http.Rewrite != nil {
errs = appendErrors(errs, errors.New("HTTP route rule cannot contain both rewrite and redirect"))
}
} else if len(http.Route) == 0 {
errs = appendErrors(errs, errors.New("HTTP route or redirect is required"))
}

// header manipulation
for name, val := range http.Headers.GetRequest().GetAdd() {
errs = appendErrors(errs, ValidateHTTPHeaderName(name))
errs = appendErrors(errs, ValidateHTTPHeaderValue(val))
}
for name, val := range http.Headers.GetRequest().GetSet() {
errs = appendErrors(errs, ValidateHTTPHeaderName(name))
errs = appendErrors(errs, ValidateHTTPHeaderValue(val))
}
for _, name := range http.Headers.GetRequest().GetRemove() {
errs = appendErrors(errs, ValidateHTTPHeaderName(name))
}
for name, val := range http.Headers.GetResponse().GetAdd() {
errs = appendErrors(errs, ValidateHTTPHeaderName(name))
errs = appendErrors(errs, ValidateHTTPHeaderValue(val))
}
for name, val := range http.Headers.GetResponse().GetSet() {
errs = appendErrors(errs, ValidateHTTPHeaderName(name))
errs = appendErrors(errs, ValidateHTTPHeaderValue(val))
}
for _, name := range http.Headers.GetResponse().GetRemove() {
errs = appendErrors(errs, ValidateHTTPHeaderName(name))
}

errs = appendErrors(errs, validateCORSPolicy(http.CorsPolicy))
errs = appendErrors(errs, validateHTTPFaultInjection(http.Fault))

for _, match := range http.Match {
if match != nil {
for name, header := range match.Headers {
if header == nil {
errs = appendErrors(errs, fmt.Errorf("header match %v cannot be null", name))
}
errs = appendErrors(errs, ValidateHTTPHeaderName(name))
errs = appendErrors(errs, validateStringMatchRegexp(header, "headers"))
}

if match.Port != 0 {
errs = appendErrors(errs, ValidatePort(int(match.Port)))
}
errs = appendErrors(errs, labels.Instance(match.SourceLabels).Validate())
errs = appendErrors(errs, validateGatewayNames(match.Gateways))
errs = appendErrors(errs, validateStringMatchRegexp(match.GetUri(), "uri"))
errs = appendErrors(errs, validateStringMatchRegexp(match.GetScheme(), "scheme"))
errs = appendErrors(errs, validateStringMatchRegexp(match.GetMethod(), "method"))
errs = appendErrors(errs, validateStringMatchRegexp(match.GetAuthority(), "authority"))
for _, qp := range match.GetQueryParams() {
errs = appendErrors(errs, validateStringMatchRegexp(qp, "queryParams"))
}
}
}

if http.MirrorPercent != nil {
if value := http.MirrorPercent.GetValue(); value > 100 {
errs = appendErrors(errs, fmt.Errorf("mirror_percent must have a max value of 100 (it has %d)", value))
}
}

if http.MirrorPercentage != nil {
if value := http.MirrorPercentage.GetValue(); value > 100 {
errs = appendErrors(errs, fmt.Errorf("mirror_percentage must have a max value of 100 (it has %f)", value))
}
}

errs = appendErrors(errs, validateDestination(http.Mirror))
errs = appendErrors(errs, validateHTTPRedirect(http.Redirect))
errs = appendErrors(errs, validateHTTPRetry(http.Retries))
errs = appendErrors(errs, validateHTTPRewrite(http.Rewrite))
errs = appendErrors(errs, validateHTTPRouteDestinations(http.Route))
if http.Timeout != nil {
errs = appendErrors(errs, ValidateDurationGogo(http.Timeout))
}

return
}

func validateStringMatchRegexp(sm *networking.StringMatch, where string) error {
re := sm.GetRegex()
if re == "" {
Expand Down
Loading

0 comments on commit 19581dd

Please sign in to comment.