...

Source file src/k8s.io/kubernetes/pkg/apis/authentication/validation/validation.go

Documentation: k8s.io/kubernetes/pkg/apis/authentication/validation

     1  /*
     2  Copyright 2018 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 contains methods to validate kinds in the
    18  // authentication.k8s.io API group.
    19  package validation
    20  
    21  import (
    22  	"time"
    23  
    24  	"k8s.io/apimachinery/pkg/util/validation/field"
    25  	"k8s.io/kubernetes/pkg/apis/authentication"
    26  )
    27  
    28  // ValidateTokenRequest validates a TokenRequest.
    29  func ValidateTokenRequest(tr *authentication.TokenRequest) field.ErrorList {
    30  	allErrs := field.ErrorList{}
    31  	specPath := field.NewPath("spec")
    32  
    33  	const min = 10 * time.Minute
    34  	if tr.Spec.ExpirationSeconds < int64(min.Seconds()) {
    35  		allErrs = append(allErrs, field.Invalid(specPath.Child("expirationSeconds"), tr.Spec.ExpirationSeconds, "may not specify a duration less than 10 minutes"))
    36  	}
    37  	if tr.Spec.ExpirationSeconds > 1<<32 {
    38  		allErrs = append(allErrs, field.Invalid(specPath.Child("expirationSeconds"), tr.Spec.ExpirationSeconds, "may not specify a duration larger than 2^32 seconds"))
    39  	}
    40  	return allErrs
    41  }
    42  

View as plain text