...

Source file src/sigs.k8s.io/gateway-api/apis/v1beta1/util/validation/gatewayclass.go

Documentation: sigs.k8s.io/gateway-api/apis/v1beta1/util/validation

     1  /*
     2  Copyright 2022 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package validation
    18  
    19  import (
    20  	"regexp"
    21  
    22  	gatewayv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1"
    23  )
    24  
    25  var controllerNameRegex = regexp.MustCompile(`^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*\/[A-Za-z0-9\/\-._~%!$&'()*+,;=:]+$`)
    26  
    27  // IsControllerNameValid checks that the provided controllerName complies with the expected
    28  // format. It must be a non-empty domain prefixed path.
    29  func IsControllerNameValid(controllerName gatewayv1b1.GatewayController) bool {
    30  	if controllerName == "" {
    31  		return false
    32  	}
    33  	return controllerNameRegex.Match([]byte(controllerName))
    34  }
    35  

View as plain text